From 85ad2b903cae20ddd22d1241805aa57bac66df4f Mon Sep 17 00:00:00 2001 From: Yan Zhu Date: Wed, 20 Sep 2023 23:16:38 +0800 Subject: [PATCH] Fix create archive to a continuous writing source file failed https://github.com/mholt/archiver/issues/387 Signed-off-by: Yan Zhu --- archiver.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/archiver.go b/archiver.go index 73ec00d4..45a5121f 100644 --- a/archiver.go +++ b/archiver.go @@ -221,8 +221,11 @@ func openAndCopyFile(file File, w io.Writer) error { return err } defer fileReader.Close() - _, err = io.Copy(w, fileReader) - return err + _, err = io.CopyN(w, fileReader, file.Size()) + if err != nil && err != io.EOF { + return err + } + return nil } // fileIsIncluded returns true if filename is included according to