修改压缩为zip方式时的堆分配
This commit is contained in:
@@ -156,24 +156,19 @@ func compress() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy the dataStream to the zip file in chunks.
|
// Copy the dataStream to the zip file in chunks.
|
||||||
for i := int64(0); ; i += chunkSize {
|
buf := make([]byte, 1024)
|
||||||
// Calculate the size of this chunk.
|
for {
|
||||||
data := make([]byte, chunkSize)
|
n, err := io.ReadAtLeast(os.Stdin, buf, 1)
|
||||||
n, err := os.Stdin.Read(data)
|
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if n == 0 {
|
||||||
// Compress this chunk.
|
break
|
||||||
_, err = writer.Write(data[:n])
|
}
|
||||||
|
_, err = writer.Write(buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we've reached the end of the dataStream.
|
|
||||||
if n < chunkSize {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user