From cdac312dd29233a3e2a12a524625726fdec9970d Mon Sep 17 00:00:00 2001 From: linxin Date: Tue, 11 Apr 2023 18:09:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8E=8B=E7=BC=A9=E4=B8=BAzi?= =?UTF-8?q?p=E6=96=B9=E5=BC=8F=E6=97=B6=E7=9A=84=E5=A0=86=E5=88=86?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- corepipe/corepipe.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/corepipe/corepipe.go b/corepipe/corepipe.go index cabf064..7857953 100644 --- a/corepipe/corepipe.go +++ b/corepipe/corepipe.go @@ -156,24 +156,19 @@ func compress() error { } // Copy the dataStream to the zip file in chunks. - for i := int64(0); ; i += chunkSize { - // Calculate the size of this chunk. - data := make([]byte, chunkSize) - n, err := os.Stdin.Read(data) + buf := make([]byte, 1024) + for { + n, err := io.ReadAtLeast(os.Stdin, buf, 1) if err != nil && err != io.EOF { return err } - - // Compress this chunk. - _, err = writer.Write(data[:n]) + if n == 0 { + break + } + _, err = writer.Write(buf[:n]) if err != nil { return err } - - // Check if we've reached the end of the dataStream. - if n < chunkSize { - break - } } return nil