From c89a9fd7b188b39f7405b99d230e6322c7e58764 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 28 Jan 2015 03:04:11 +0200 Subject: [PATCH] gzip: Implement decompress() function. --- gzip/gzip.py | 28 ++++++++++++++++++++++++++++ gzip/metadata.txt | 4 ++-- gzip/setup.py | 6 +++--- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/gzip/gzip.py b/gzip/gzip.py index e69de29b..be4e8f4a 100644 --- a/gzip/gzip.py +++ b/gzip/gzip.py @@ -0,0 +1,28 @@ +#import zlib +import uzlib as zlib + +FTEXT = 1 +FHCRC = 2 +FEXTRA = 4 +FNAME = 8 +FCOMMENT = 16 + +def decompress(data): + assert data[0] == 0x1f and data[1] == 0x8b + assert data[2] == 8 + flg = data[3] + assert flg & 0xe0 == 0 + i = 10 + if flg & FEXTRA: + i += data[11] << 8 + data[10] + 2 + if flg & FNAME: + while data[i]: + i += 1 + i += 1 + if flg & FCOMMENT: + while data[i]: + i += 1 + i += 1 + if flg & FHCRC: + i += 2 + return zlib.decompress(memoryview(data)[i:], -15) diff --git a/gzip/metadata.txt b/gzip/metadata.txt index 34e7b20b..6b5dc732 100644 --- a/gzip/metadata.txt +++ b/gzip/metadata.txt @@ -1,3 +1,3 @@ -srctype=dummy +srctype=micropython-lib type=module -version=0.0.1 +version=0.1 diff --git a/gzip/setup.py b/gzip/setup.py index aeb1460e..b2287005 100644 --- a/gzip/setup.py +++ b/gzip/setup.py @@ -6,9 +6,9 @@ from setuptools import setup setup(name='micropython-gzip', - version='0.0.1', - description='Dummy gzip module for MicroPython', - 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.', + version='0.1', + description='gzip module for MicroPython', + 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.", url='https://github.com/micropython/micropython/issues/405', author='MicroPython Developers', author_email='micro-python@googlegroups.com',