Skip to content

Commit 3533924

Browse files
jimmodpgeorge
authored andcommitted
extmod/moddeflate: Add deflate module providing the DeflateIO class.
This provides similar functionality to the former zlib.DecompIO and especially CPython's gzip.GzipFile for both compression and decompression. This class can be used directly, and also can be used from Python to implement (via io.BytesIO) zlib.decompress and zlib.compress, as well as gzip.GzipFile. Enable/disable this on all ports/boards that zlib was previously configured for. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
1 parent e6c290c commit 3533924

File tree

12 files changed

+434
-10
lines changed

12 files changed

+434
-10
lines changed

extmod/extmod.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ set(MICROPY_SOURCE_EXTMOD
2323
${MICROPY_EXTMOD_DIR}/modbinascii.c
2424
${MICROPY_EXTMOD_DIR}/modcryptolib.c
2525
${MICROPY_EXTMOD_DIR}/moductypes.c
26+
${MICROPY_EXTMOD_DIR}/moddeflate.c
2627
${MICROPY_EXTMOD_DIR}/modhashlib.c
2728
${MICROPY_EXTMOD_DIR}/modheapq.c
2829
${MICROPY_EXTMOD_DIR}/modjson.c

extmod/extmod.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SRC_EXTMOD_C += \
1616
extmod/modbluetooth.c \
1717
extmod/modbtree.c \
1818
extmod/modcryptolib.c \
19+
extmod/moddeflate.c \
1920
extmod/modframebuf.c \
2021
extmod/modhashlib.c \
2122
extmod/modheapq.c \

extmod/modbinascii.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ STATIC mp_obj_t mod_binascii_b2a_base64(size_t n_args, const mp_obj_t *pos_args,
170170
}
171171
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_binascii_b2a_base64_obj, 1, mod_binascii_b2a_base64);
172172

173-
#if 0 // MICROPY_PY_BINASCII_CRC32
174-
#include "lib/uzlib/crc32.c"
173+
#if MICROPY_PY_BINASCII_CRC32 && MICROPY_PY_DEFLATE
174+
#include "lib/uzlib/uzlib.h"
175175

176176
STATIC mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) {
177177
mp_buffer_info_t bufinfo;
@@ -191,7 +191,7 @@ STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = {
191191
#endif
192192
{ MP_ROM_QSTR(MP_QSTR_a2b_base64), MP_ROM_PTR(&mod_binascii_a2b_base64_obj) },
193193
{ MP_ROM_QSTR(MP_QSTR_b2a_base64), MP_ROM_PTR(&mod_binascii_b2a_base64_obj) },
194-
#if 0 // MICROPY_PY_BINASCII_CRC32
194+
#if MICROPY_PY_BINASCII_CRC32 && MICROPY_PY_DEFLATE
195195
{ MP_ROM_QSTR(MP_QSTR_crc32), MP_ROM_PTR(&mod_binascii_crc32_obj) },
196196
#endif
197197
};

0 commit comments

Comments
 (0)