1
0
Fork 0

Tweak chunker

master
Philip O'Toole 1 year ago
parent a0c278f1dc
commit 5f35c64c06

@ -26,7 +26,11 @@ var bufferPool = sync.Pool{
// Define a sync.Pool to pool the gzip writers. // Define a sync.Pool to pool the gzip writers.
var gzipWriterPool = sync.Pool{ var gzipWriterPool = sync.Pool{
New: func() interface{} { New: func() interface{} {
return gzip.NewWriter(nil) gw, err := gzip.NewWriterLevel(nil, gzip.BestCompression)
if err != nil {
panic(fmt.Sprintf("failed to create gzip writer: %s", err.Error()))
}
return gw
}, },
} }
@ -94,6 +98,7 @@ func (c *Chunker) Next() (*command.LoadChunkRequest, error) {
} }
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
c.finished = true
break break
} else { } else {
return nil, err return nil, err
@ -106,13 +111,9 @@ func (c *Chunker) Next() (*command.LoadChunkRequest, error) {
return nil, errors.New("failed to close gzip writer: " + err.Error()) return nil, errors.New("failed to close gzip writer: " + err.Error())
} }
if totalRead < c.chunkSize { // If we didn't read any data, then we're finished
c.finished = true
}
// If we didn't write any data, then we're finished
if totalRead == 0 { if totalRead == 0 {
// If no previous chunks were sent at all signal that. // If no previous chunks were sent at all then signal that.
if c.sequenceNum == 0 { if c.sequenceNum == 0 {
return nil, io.EOF return nil, io.EOF
} }

Loading…
Cancel
Save