diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-01-28 02:10:53 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-01-28 02:21:49 +0200 |
commit | 2324f3ef2912fe4f82b9560e14eec1f7b6b5de5a (patch) | |
tree | ada6a33cb08411db20ba512bdef51d98dc4ddbfa | |
parent | 0b3014ce3ac381e886c956137e4e5475061a5ddc (diff) | |
download | micropython-2324f3ef2912fe4f82b9560e14eec1f7b6b5de5a.tar.gz micropython-2324f3ef2912fe4f82b9560e14eec1f7b6b5de5a.zip |
moduzlib: Implement raw DEFLATE decoding support.
-rw-r--r-- | extmod/moduzlib.c | 7 | ||||
-rw-r--r-- | tests/extmod/zlibd_decompress.py | 8 |
2 files changed, 14 insertions, 1 deletions
diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c index 821f300dab..30e5a05e43 100644 --- a/extmod/moduzlib.c +++ b/extmod/moduzlib.c @@ -68,7 +68,12 @@ STATIC mp_obj_t mod_uzlib_decompress(mp_uint_t n_args, const mp_obj_t *args) { decomp->destGrow = mod_uzlib_grow_buf; decomp->source = bufinfo.buf; - int st = tinf_zlib_uncompress_dyn(decomp, bufinfo.len); + int st; + if (n_args > 1 && MP_OBJ_SMALL_INT_VALUE(args[1]) < 0) { + st = tinf_uncompress_dyn(decomp); + } else { + st = tinf_zlib_uncompress_dyn(decomp, bufinfo.len); + } if (st != 0) { nlr_raise(mp_obj_new_exception_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st))); } diff --git a/tests/extmod/zlibd_decompress.py b/tests/extmod/zlibd_decompress.py index 64df6da2ef..041cabdfe1 100644 --- a/tests/extmod/zlibd_decompress.py +++ b/tests/extmod/zlibd_decompress.py @@ -14,3 +14,11 @@ PATTERNS = [ for unpacked, packed in PATTERNS: assert zlib.decompress(packed) == unpacked print(unpacked) + + +# Raw DEFLATE bitstream +v = b'\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00' +exp = b"hello" +out = zlib.decompress(v, -15) +assert(out == exp) +print(exp) |