|
@@ -170,7 +170,14 @@ func Push(ctx context.Context, ref reference.Named, imagePushConfig *ImagePushCo
|
|
// argument so that it can be used with httpBlobWriter's ReadFrom method.
|
|
// argument so that it can be used with httpBlobWriter's ReadFrom method.
|
|
// Using httpBlobWriter's Write method would send a PATCH request for every
|
|
// Using httpBlobWriter's Write method would send a PATCH request for every
|
|
// Write call.
|
|
// Write call.
|
|
-func compress(in io.Reader) io.ReadCloser {
|
|
|
|
|
|
+//
|
|
|
|
+// The second return value is a channel that gets closed when the goroutine
|
|
|
|
+// is finished. This allows the caller to make sure the goroutine finishes
|
|
|
|
+// before it releases any resources connected with the reader that was
|
|
|
|
+// passed in.
|
|
|
|
+func compress(in io.Reader) (io.ReadCloser, chan struct{}) {
|
|
|
|
+ compressionDone := make(chan struct{})
|
|
|
|
+
|
|
pipeReader, pipeWriter := io.Pipe()
|
|
pipeReader, pipeWriter := io.Pipe()
|
|
// Use a bufio.Writer to avoid excessive chunking in HTTP request.
|
|
// Use a bufio.Writer to avoid excessive chunking in HTTP request.
|
|
bufWriter := bufio.NewWriterSize(pipeWriter, compressionBufSize)
|
|
bufWriter := bufio.NewWriterSize(pipeWriter, compressionBufSize)
|
|
@@ -189,7 +196,8 @@ func compress(in io.Reader) io.ReadCloser {
|
|
} else {
|
|
} else {
|
|
pipeWriter.Close()
|
|
pipeWriter.Close()
|
|
}
|
|
}
|
|
|
|
+ close(compressionDone)
|
|
}()
|
|
}()
|
|
|
|
|
|
- return pipeReader
|
|
|
|
|
|
+ return pipeReader, compressionDone
|
|
}
|
|
}
|