修改压缩为zip方式时的堆分配

This commit is contained in:
linxin
2023-04-11 18:09:40 +08:00
parent f1fb517c3a
commit cdac312dd2

View File

@@ -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