Skip to content

Commit c89a9fd

Browse files
committed
gzip: Implement decompress() function.
1 parent caa1b27 commit c89a9fd

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

gzip/gzip.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#import zlib
2+
import uzlib as zlib
3+
4+
FTEXT = 1
5+
FHCRC = 2
6+
FEXTRA = 4
7+
FNAME = 8
8+
FCOMMENT = 16
9+
10+
def decompress(data):
11+
assert data[0] == 0x1f and data[1] == 0x8b
12+
assert data[2] == 8
13+
flg = data[3]
14+
assert flg & 0xe0 == 0
15+
i = 10
16+
if flg & FEXTRA:
17+
i += data[11] << 8 + data[10] + 2
18+
if flg & FNAME:
19+
while data[i]:
20+
i += 1
21+
i += 1
22+
if flg & FCOMMENT:
23+
while data[i]:
24+
i += 1
25+
i += 1
26+
if flg & FHCRC:
27+
i += 2
28+
return zlib.decompress(memoryview(data)[i:], -15)

gzip/metadata.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
srctype=dummy
1+
srctype=micropython-lib
22
type=module
3-
version=0.0.1
3+
version=0.1

gzip/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77

88
setup(name='micropython-gzip',
9-
version='0.0.1',
10-
description='Dummy gzip module for MicroPython',
11-
long_description='This is a dummy implementation of a module for MicroPython standard library.\nIt contains zero or very little functionality, and primarily intended to\navoid import errors (using idea that even if an application imports a\nmodule, it may be not using it onevery code path, so may work at least\npartially). It is expected that more complete implementation of the module\nwill be provided later. Please help with the development if you are\ninterested in this module.',
9+
version='0.1',
10+
description='gzip module for MicroPython',
11+
long_description="This is a module reimplemented specifically for MicroPython standard library,\nwith efficient and lean design in mind. Note that this module is likely work\nin progress and likely supports just a subset of CPython's corresponding\nmodule. Please help with the development if you are interested in this\nmodule.",
1212
url='https://github.com/micropython/micropython/issues/405',
1313
author='MicroPython Developers',
1414
author_email='[email protected]',

0 commit comments

Comments
 (0)