summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlinxin <[email protected]>2023-04-11 18:09:40 +0800
committerlinxin <[email protected]>2023-04-11 18:09:40 +0800
commitcdac312dd29233a3e2a12a524625726fdec9970d (patch)
treeb3b8605c6fc5d1e08a0c274e4f76e1dcfd7e1572
parentf1fb517c3a0390873c2a36421e31e09fcb62512f (diff)
修改压缩为zip方式时的堆分配
-rw-r--r--corepipe/corepipe.go19
1 files 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