Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 1bc5cb4

Browse files
author
Paul Sokolovsky
committed
extmod/moduzlib: Support wbits arg to DecompIO.
1 parent fedab99 commit 1bc5cb4

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

extmod/moduzlib.c

+18-4
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,31 @@ STATIC unsigned char read_src_stream(TINF_DATA *data) {
6767
return c;
6868
}
6969

70-
#define DICT_SIZE 32768
71-
7270
STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
73-
mp_arg_check_num(n_args, n_kw, 1, 1, false);
71+
mp_arg_check_num(n_args, n_kw, 1, 2, false);
7472
mp_obj_decompio_t *o = m_new_obj(mp_obj_decompio_t);
7573
o->base.type = type;
7674
memset(&o->decomp, 0, sizeof(o->decomp));
77-
uzlib_uncompress_init(&o->decomp, m_new(byte, DICT_SIZE), DICT_SIZE);
7875
o->decomp.readSource = read_src_stream;
7976
o->src_stream = args[0];
8077
o->eof = false;
78+
79+
mp_int_t dict_opt = 0;
80+
int dict_sz;
81+
if (n_args > 1) {
82+
dict_opt = mp_obj_get_int(args[1]);
83+
}
84+
if (dict_opt >= 0) {
85+
dict_opt = uzlib_zlib_parse_header(&o->decomp);
86+
if (dict_opt < 0) {
87+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "zlib header"));
88+
}
89+
dict_sz = 1 << dict_opt;
90+
} else {
91+
dict_sz = 1 << -dict_opt;
92+
}
93+
94+
uzlib_uncompress_init(&o->decomp, m_new(byte, dict_sz), dict_sz);
8195
return MP_OBJ_FROM_PTR(o);
8296
}
8397

0 commit comments

Comments
 (0)