8000 extmod/moduzlib: DecompIO: Add support for gzip-formatted streams. · sparkfun/circuitpython@7b901d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b901d6

Browse files
committed
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.
1 parent d8a4d9d commit 7b901d6

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

extmod/moduzlib.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,18 @@ STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, size
8181
if (n_args > 1) {
8282
dict_opt = mp_obj_get_int(args[1]);
8383
}
84-
if (dict_opt >= 0) {
84+
85+
if (dict_opt >= 16) {
86+
int st = uzlib_gzip_parse_header(&o->decomp);
87+
if (st != TINF_OK) {
88+
goto header_error;
89+
}
90+
dict_sz = 1 << (dict_opt - 16);
91+
} else if (dict_opt >= 0) {
8592
dict_opt = uzlib_zlib_parse_header(&o->decomp);
8693
if (dict_opt < 0) {
87-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "zlib header"));
94+
header_error:
95+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "compression header"));
8896
}
8997
dict_sz = 1 << dict_opt;
9098
} else {
@@ -212,6 +220,7 @@ const mp_obj_module_t mp_module_uzlib = {
212220

213221
#include "uzlib/tinflate.c"
214222
#include "uzlib/tinfzlib.c"
223+
#include "uzlib/tinfgzip.c"
215224
#include "uzlib/adler32.c"
216225
#include "uzlib/crc32.c"
217226

0 commit comments

Comments
 (0)
0