diff --git a/util/dockerloadformat.py b/util/dockerloadformat.py index 3b1f59e89..71f9b4d00 100644 --- a/util/dockerloadformat.py +++ b/util/dockerloadformat.py @@ -1,4 +1,4 @@ -from util.gzipwrap import GzipWrap +from util.gzipwrap import GzipWrap, GZIP_BUFFER_SIZE from util.streamlayerformat import StreamLayerMerger from app import app @@ -75,7 +75,11 @@ def _import_format_generator(namespace, repository, tag, synthetic_image_id, # If the yielded size is less than the estimated size (which is likely), fill the rest with # zeros. if yielded_size < estimated_file_size: - yield '\0' * (estimated_file_size - yielded_size) + to_yield = estimated_file_size - yielded_size + while to_yield > 0: + yielded = min(to_yield, GZIP_BUFFER_SIZE) + yield '\0' * yielded + to_yield -= yielded # Yield any file padding to 512 bytes that is necessary. yield _tar_file_padding(estimated_file_size) diff --git a/util/gzipwrap.py b/util/gzipwrap.py index 037196c5e..3e5dc6bdd 100644 --- a/util/gzipwrap.py +++ b/util/gzipwrap.py @@ -1,5 +1,8 @@ from gzip import GzipFile +# 256K buffer to Gzip +GZIP_BUFFER_SIZE = 1024 * 256 + class GzipWrap(object): def __init__(self, input, filename=None, compresslevel=1): self.input = iter(input) @@ -21,7 +24,7 @@ class GzipWrap(object): input_size = 0 input_buffer = '' - while input_size < 1024 * 256: # 256K buffer to Gzip + while input_size < GZIP_BUFFER_SIZE: try: s = self.input.next() input_buffer += s