Skip to content

Commit a62fa59

Browse files
authored
Merge pull request #4 from jakirkham/use_gzipfile_obj
Use gzip's GzipFile to manage compression/decompression
2 parents 3a80a7d + 1c9de0f commit a62fa59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+18
-12
lines changed

README.rst

Lines changed: 6 additions & 6 deletions

fixture/gzip/array.02.npy

0 Bytes
Binary file not shown.

fixture/gzip/array.03.npy

0 Bytes
Binary file not shown.

fixture/gzip/array.04.npy

0 Bytes
Binary file not shown.

fixture/gzip/array.05.npy

0 Bytes
Binary file not shown.

fixture/gzip/array.06.npy

0 Bytes
Binary file not shown.

fixture/gzip/array.07.npy

0 Bytes
Binary file not shown.

fixture/gzip/array.08.npy

0 Bytes
Binary file not shown.

fixture/gzip/codec.00/encoded.00.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.00/encoded.01.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.00/encoded.02.dat

-1 Bytes
Binary file not shown.

fixture/gzip/codec.00/encoded.03.dat

-3 Bytes
Binary file not shown.

fixture/gzip/codec.00/encoded.04.dat

13 Bytes
Binary file not shown.

fixture/gzip/codec.00/encoded.05.dat

4 Bytes
Binary file not shown.

fixture/gzip/codec.00/encoded.06.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.00/encoded.07.dat

-5 Bytes
Binary file not shown.

fixture/gzip/codec.00/encoded.08.dat

-10 Bytes
Binary file not shown.

fixture/gzip/codec.01/encoded.00.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.01/encoded.01.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.01/encoded.02.dat

-5 Bytes
Binary file not shown.

fixture/gzip/codec.01/encoded.03.dat

-5 Bytes
Binary file not shown.

fixture/gzip/codec.01/encoded.04.dat

-12 Bytes
Binary file not shown.

fixture/gzip/codec.01/encoded.05.dat

4 Bytes
Binary file not shown.

fixture/gzip/codec.01/encoded.06.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.01/encoded.07.dat

-6 Bytes
Binary file not shown.

fixture/gzip/codec.01/encoded.08.dat

-12 Bytes
Binary file not shown.

fixture/gzip/codec.02/encoded.00.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.02/encoded.01.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.02/encoded.02.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.02/encoded.03.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.02/encoded.04.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.02/encoded.05.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.02/encoded.06.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.02/encoded.07.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.02/encoded.08.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.03/encoded.00.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.03/encoded.01.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.03/encoded.02.dat

-1 Bytes
Binary file not shown.

fixture/gzip/codec.03/encoded.03.dat

-3 Bytes
Binary file not shown.

fixture/gzip/codec.03/encoded.04.dat

13 Bytes
Binary file not shown.

fixture/gzip/codec.03/encoded.05.dat

4 Bytes
Binary file not shown.

fixture/gzip/codec.03/encoded.06.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.03/encoded.07.dat

-5 Bytes
Binary file not shown.

fixture/gzip/codec.03/encoded.08.dat

-10 Bytes
Binary file not shown.

fixture/gzip/codec.04/encoded.00.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.04/encoded.01.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.04/encoded.02.dat

-7 Bytes
Binary file not shown.

fixture/gzip/codec.04/encoded.03.dat

-1 Bytes
Binary file not shown.

fixture/gzip/codec.04/encoded.04.dat

-5 Bytes
Binary file not shown.

fixture/gzip/codec.04/encoded.05.dat

4 Bytes
Binary file not shown.

fixture/gzip/codec.04/encoded.06.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.04/encoded.07.dat

-7 Bytes
Binary file not shown.

fixture/gzip/codec.04/encoded.08.dat

-16 Bytes
Binary file not shown.

fixture/gzip/codec.05/encoded.00.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.05/encoded.01.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.05/encoded.02.dat

-5 Bytes
Binary file not shown.

fixture/gzip/codec.05/encoded.03.dat

-5 Bytes
Binary file not shown.

fixture/gzip/codec.05/encoded.04.dat

-16 Bytes
Binary file not shown.

fixture/gzip/codec.05/encoded.05.dat

4 Bytes
Binary file not shown.

fixture/gzip/codec.05/encoded.06.dat

0 Bytes
Binary file not shown.

fixture/gzip/codec.05/encoded.07.dat

-13 Bytes
Binary file not shown.

fixture/gzip/codec.05/encoded.08.dat

-22 Bytes
Binary file not shown.

numcodecs/gzip.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, print_function, division
3-
import zlib as _zlib
3+
import gzip as _gzip
4+
import io
45

56

67
import numpy as np
@@ -45,9 +46,12 @@ def encode(self, buf):
4546
buf = buffer_tobytes(buf)
4647

4748
# do compression
48-
compress = _zlib.compressobj(self.level, _zlib.DEFLATED, 16 + 15)
49-
compressed = compress.compress(buf)
50-
compressed += compress.flush()
49+
compressed = io.BytesIO()
50+
with _gzip.GzipFile(fileobj=compressed,
51+
mode='wb',
52+
compresslevel=self.level) as compressor:
53+
compressor.write(buf)
54+
compressed = compressed.getvalue()
5155

5256
return compressed
5357

@@ -59,9 +63,11 @@ def decode(self, buf, out=None):
5963
buf = buffer_tobytes(buf)
6064

6165
# do decompression
62-
dec = _zlib.decompress(buf, 15 + 32)
66+
buf = io.BytesIO(buf)
67+
with _gzip.GzipFile(fileobj=buf, mode='rb') as decompressor:
68+
decompressed = decompressor.read()
6369

6470
# handle destination - Python standard library zlib module does not
6571
# support direct decompression into buffer, so we have to copy into
6672
# out if given
67-
return buffer_copy(dec, out)
73+
return buffer_copy(decompressed, out)

0 commit comments

Comments
 (0)