Skip to content

Commit 2324f3e

Browse files
committed
moduzlib: Implement raw DEFLATE decoding support.
1 parent 0b3014c commit 2324f3e

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

extmod/moduzlib.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ STATIC mp_obj_t mod_uzlib_decompress(mp_uint_t n_args, const mp_obj_t *args) {
6868
decomp->destGrow = mod_uzlib_grow_buf;
6969
decomp->source = bufinfo.buf;
7070

71-
int st = tinf_zlib_uncompress_dyn(decomp, bufinfo.len);
71+
int st;
72+
if (n_args > 1 && MP_OBJ_SMALL_INT_VALUE(args[1]) < 0) {
73+
st = tinf_uncompress_dyn(decomp);
74+
} else {
75+
st = tinf_zlib_uncompress_dyn(decomp, bufinfo.len);
76+
}
7277
if (st != 0) {
7378
nlr_raise(mp_obj_new_exception_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st)));
7479
}

tests/extmod/zlibd_decompress.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@
1414
for unpacked, packed in PATTERNS:
1515
assert zlib.decompress(packed) == unpacked
1616
print(unpacked)
17+
18+
19+
# Raw DEFLATE bitstream
20+
v = b'\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00'
21+
exp = b"hello"
22+
out = zlib.decompress(v, -15)
23+
assert(out == exp)
24+
print(exp)

0 commit comments

Comments
 (0)