summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-09-24 15:30:11 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-09-24 15:30:11 +0300
commit7b901d6fb7e136c23cf6b728179bd86f9c9bd95e (patch)
treea0c645a28e10b131c0d44fe451b2ec345a15bb7f
parentd8a4d9d67c16c5c827ed5c70c4d9d8042f9273cb (diff)
downloadmicropython-7b901d6fb7e136c23cf6b728179bd86f9c9bd95e.tar.gz
micropython-7b901d6fb7e136c23cf6b728179bd86f9c9bd95e.zip
extmod/moduzlib: DecompIO: Add support for gzip-formatted streams.
This uses extension introduced in CPython 3.5: if wbits (dictionary size code) has value 16 + 8..15, it means that gzip-formatted stream expected.
-rw-r--r--extmod/moduzlib.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c
index 68a087bc1c..b0e0b005e3 100644
--- a/extmod/moduzlib.c
+++ b/extmod/moduzlib.c
@@ -81,10 +81,18 @@ STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, size
if (n_args > 1) {
dict_opt = mp_obj_get_int(args[1]);
}
- if (dict_opt >= 0) {
+
+ if (dict_opt >= 16) {
+ int st = uzlib_gzip_parse_header(&o->decomp);
+ if (st != TINF_OK) {
+ goto header_error;
+ }
+ dict_sz = 1 << (dict_opt - 16);
+ } else if (dict_opt >= 0) {
dict_opt = uzlib_zlib_parse_header(&o->decomp);
if (dict_opt < 0) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "zlib header"));
+header_error:
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "compression header"));
}
dict_sz = 1 << dict_opt;
} else {
@@ -212,6 +220,7 @@ const mp_obj_module_t mp_module_uzlib = {
#include "uzlib/tinflate.c"
#include "uzlib/tinfzlib.c"
+#include "uzlib/tinfgzip.c"
#include "uzlib/adler32.c"
#include "uzlib/crc32.c"