Renaming and documentation
This commit is contained in:
parent
ba229f1007
commit
664e02535b
|
@ -3016,7 +3016,7 @@ msgstr ""
|
|||
msgid "complex values not supported"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/moduzlib.c
|
||||
#: extmod/moduzlib.c shared-module/zlib/DecompIO.c
|
||||
msgid "compression header"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -321,8 +321,8 @@ endif
|
|||
ifeq ($(CIRCUITPY_USTACK),1)
|
||||
SRC_PATTERNS += ustack/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_UZLIB),1)
|
||||
SRC_PATTERNS += uzlib/%
|
||||
ifeq ($(CIRCUITPY_ZLIB),1)
|
||||
SRC_PATTERNS += zlib/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_VIDEOCORE),1)
|
||||
SRC_PATTERNS += videocore/%
|
||||
|
@ -581,8 +581,8 @@ SRC_SHARED_MODULE_ALL = \
|
|||
traceback/__init__.c \
|
||||
uheap/__init__.c \
|
||||
ustack/__init__.c \
|
||||
uzlib/__init__.c \
|
||||
uzlib/DecompIO.c \
|
||||
zlib/__init__.c \
|
||||
zlib/DecompIO.c \
|
||||
vectorio/Circle.c \
|
||||
vectorio/Polygon.c \
|
||||
vectorio/Rectangle.c \
|
||||
|
@ -639,7 +639,7 @@ SRC_MOD += $(addprefix lib/protomatter/src/, \
|
|||
$(BUILD)/lib/protomatter/src/core.o: CFLAGS += -include "shared-module/rgbmatrix/allocator.h" -DCIRCUITPY -Wno-missing-braces -Wno-missing-prototypes
|
||||
endif
|
||||
|
||||
ifeq ($(CIRCUITPY_UZLIB),1)
|
||||
ifeq ($(CIRCUITPY_ZLIB),1)
|
||||
SRC_MOD += $(addprefix lib/uzlib/, \
|
||||
tinflate.c \
|
||||
tinfzlib.c \
|
||||
|
|
|
@ -447,8 +447,8 @@ CIRCUITPY_USTACK ?= 0
|
|||
CFLAGS += -DCIRCUITPY_USTACK=$(CIRCUITPY_USTACK)
|
||||
|
||||
# for decompressing utlities
|
||||
CIRCUITPY_UZLIB ?= 1
|
||||
CFLAGS += -DCIRCUITPY_UZLIB=$(CIRCUITPY_UZLIB)
|
||||
CIRCUITPY_ZLIB ?= 1
|
||||
CFLAGS += -DCIRCUITPY_ZLIB=$(CIRCUITPY_ZLIB)
|
||||
|
||||
# ulab numerics library
|
||||
CIRCUITPY_ULAB ?= $(CIRCUITPY_FULL_BUILD)
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2022 Mark Komus
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "py/obj.h"
|
||||
#include "py/stream.h"
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/uzlib/DecompIO.h"
|
||||
#include "shared-module/uzlib/DecompIO.h"
|
||||
|
||||
STATIC mp_obj_t uzlib_decompio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 2, false);
|
||||
mp_get_stream_raise(args[0], MP_STREAM_OP_READ);
|
||||
|
||||
mp_obj_decompio_t *self = m_new_obj(mp_obj_decompio_t);
|
||||
self->base.type = type;
|
||||
memset(&self->decomp, 0, sizeof(self->decomp));
|
||||
|
||||
mp_int_t dict_opt = 0;
|
||||
if (n_args > 1) {
|
||||
dict_opt = mp_obj_get_int(args[1]);
|
||||
}
|
||||
|
||||
common_hal_uzlib_decompio_construct(self, args[0], dict_opt);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC mp_uint_t uzlib_decompio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
||||
mp_obj_decompio_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (self->eof) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return common_hal_uzlib_decompio_read(self, buf, size, errcode);
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t decompio_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(decompio_locals_dict, decompio_locals_dict_table);
|
||||
|
||||
STATIC const mp_stream_p_t decompio_stream_p = {
|
||||
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
|
||||
.read = uzlib_decompio_read,
|
||||
.write = NULL,
|
||||
.ioctl = NULL,
|
||||
.is_text = false,
|
||||
};
|
||||
|
||||
const mp_obj_type_t decompio_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_DecompIO,
|
||||
.make_new = uzlib_decompio_make_new,
|
||||
.locals_dict = (void *)&decompio_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &decompio_stream_p,
|
||||
),
|
||||
};
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2022 Mark Komus
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/builtin.h"
|
||||
#include "py/objtuple.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/parsenum.h"
|
||||
|
||||
#include "shared-bindings/uzlib/DecompIO.h"
|
||||
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
#include "shared-bindings/uzlib/__init__.h"
|
||||
#include "shared-bindings/uzlib/DecompIO.h"
|
||||
|
||||
STATIC mp_obj_t uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
||||
// TODO: Check number of args
|
||||
|
||||
bool is_zlib = true;
|
||||
if (n_args > 1 && MP_OBJ_SMALL_INT_VALUE(args[1]) < 0) {
|
||||
is_zlib = false;
|
||||
}
|
||||
|
||||
return common_hal_uzlib_decompress(args[0], is_zlib);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(uzlib_decompress_obj, 1, 3, uzlib_decompress);
|
||||
|
||||
STATIC const mp_rom_map_elem_t uzlib_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uzlib) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&uzlib_decompress_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DecompIO), MP_ROM_PTR(&decompio_type) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(uzlib_globals, uzlib_globals_table);
|
||||
|
||||
const mp_obj_module_t uzlib_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t *)&uzlib_globals,
|
||||
};
|
||||
|
||||
MP_REGISTER_MODULE(MP_QSTR_uzlib, uzlib_module, CIRCUITPY_UZLIB);
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2022 Mark Komus
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "py/obj.h"
|
||||
#include "py/stream.h"
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/zlib/DecompIO.h"
|
||||
#include "shared-module/zlib/DecompIO.h"
|
||||
|
||||
//| class DecompIO:
|
||||
//| """A stream wrapper which allows transparent decompression of compressed data in
|
||||
//| another stream. This allows to process compressed streams with data larger
|
||||
//| than available heap size.
|
||||
//|
|
||||
//| *wbits* is DEFLATE dictionary window size used during compression (8-15, the
|
||||
//| dictionary size is power of 2 of that value). Additionally, if value is positive,
|
||||
//| *data* is assumed to be zlib stream (with zlib header). Otherwise, if it's
|
||||
//| negative, it's assumed to be raw DEFLATE stream. *wbits* values 24..31 (16 + 8..15)
|
||||
//| mean that input stream has gzip header."""
|
||||
//|
|
||||
//| def __init__(self, stream: IO[AnyStr], wbits: Optional[int] = 0) -> None:
|
||||
//| """Creates a DecompIO object to decompress stream data.
|
||||
//| """
|
||||
//| ...
|
||||
//|
|
||||
|
||||
// These are standard stream methods. Code is in py/stream.c.
|
||||
//
|
||||
//| def read(self, nbytes: Optional[int] = None) -> Optional[bytes]:
|
||||
//| """Read characters. If ``nbytes`` is specified then read at most that many
|
||||
//| bytes. Otherwise, read everything that arrives until the connection
|
||||
//| times out. Providing the number of bytes expected is highly recommended
|
||||
//| because it will be faster.
|
||||
//|
|
||||
//| :return: Data read
|
||||
//| :rtype: bytes or None"""
|
||||
//| ...
|
||||
//|
|
||||
//| def readinto(self, buf: WriteableBuffer, nbytes: Optional[int] = None) -> Optional[bytes]:
|
||||
//| """Read bytes into the ``buf``. If ``nbytes`` is specified then read at most
|
||||
//| that many bytes. Otherwise, read at most ``len(buf)`` bytes.
|
||||
//|
|
||||
//| :return: number of bytes read and stored into ``buf``
|
||||
//| :rtype: bytes or None"""
|
||||
//| ...
|
||||
//|
|
||||
//| def readline(self, nbytes: Optional[int] = None) -> Optional[bytes]:
|
||||
//| """Read and return one line from the stream. The line terminator is always b'\n'.
|
||||
//| If ``nbytes`` is specified then read at most that many bytes.
|
||||
//|
|
||||
//| :return: Data read
|
||||
//| :rtype: bytes or None"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t zlib_decompio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 2, false);
|
||||
mp_get_stream_raise(args[0], MP_STREAM_OP_READ);
|
||||
|
||||
mp_obj_decompio_t *self = m_new_obj(mp_obj_decompio_t);
|
||||
self->base.type = type;
|
||||
memset(&self->decomp, 0, sizeof(self->decomp));
|
||||
|
||||
mp_int_t dict_opt = 0;
|
||||
if (n_args > 1) {
|
||||
dict_opt = mp_obj_get_int(args[1]);
|
||||
}
|
||||
|
||||
common_hal_zlib_decompio_construct(self, args[0], dict_opt);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC mp_uint_t zlib_decompio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
|
||||
mp_obj_decompio_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (self->eof) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return common_hal_zlib_decompio_read(self, buf, size, errcode);
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t decompio_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(decompio_locals_dict, decompio_locals_dict_table);
|
||||
|
||||
STATIC const mp_stream_p_t decompio_stream_p = {
|
||||
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
|
||||
.read = zlib_decompio_read,
|
||||
.write = NULL,
|
||||
.ioctl = NULL,
|
||||
.is_text = false,
|
||||
};
|
||||
|
||||
const mp_obj_type_t decompio_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_DecompIO,
|
||||
.make_new = zlib_decompio_make_new,
|
||||
.locals_dict = (void *)&decompio_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &decompio_stream_p,
|
||||
),
|
||||
};
|
|
@ -24,14 +24,14 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_UZLIB_DECOMPIO_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_UZLIB_DECOMPIO_H
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB_DECOMPIO_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB_DECOMPIO_H
|
||||
|
||||
#include "shared-module/uzlib/DecompIO.h"
|
||||
#include "shared-module/zlib/DecompIO.h"
|
||||
|
||||
extern const mp_obj_type_t decompio_type;
|
||||
|
||||
extern void common_hal_uzlib_decompio_construct(mp_obj_decompio_t *self, mp_obj_t src_stream, mp_int_t dict_opt);
|
||||
extern mp_uint_t common_hal_uzlib_decompio_read(mp_obj_decompio_t *self, void *buf, mp_uint_t size, int *errcode);
|
||||
extern void common_hal_zlib_decompio_construct(mp_obj_decompio_t *self, mp_obj_t src_stream, mp_int_t dict_opt);
|
||||
extern mp_uint_t common_hal_zlib_decompio_read(mp_obj_decompio_t *self, void *buf, mp_uint_t size, int *errcode);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_UZLIB_DECOMPIO_H
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB_DECOMPIO_H
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2022 Mark Komus
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/builtin.h"
|
||||
#include "py/objtuple.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/parsenum.h"
|
||||
|
||||
#include "shared-bindings/zlib/DecompIO.h"
|
||||
#include "shared-bindings/zlib/__init__.h"
|
||||
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| """zlib decompression functionality
|
||||
//|
|
||||
//| The `zlib` module allows limited functionality similar to the CPython zlib library.
|
||||
//| This module allows to decompress binary data compressed with DEFLATE algorithm
|
||||
//| (commonly used in zlib library and gzip archiver). Compression is not yet implemented."""
|
||||
//|
|
||||
|
||||
//| def zlib_decompress(data: bytes, wbits: Optional[int] = 0, bufsize: Optional[int] = 0) -> bytes:
|
||||
//| """Return decompressed *data* as bytes. *wbits* is DEFLATE dictionary window
|
||||
//| size used during compression (8-15, the dictionary size is power of 2 of
|
||||
//| that value). Additionally, if value is positive, *data* is assumed to be
|
||||
//| zlib stream (with zlib header). Otherwise, if it's negative, it's assumed
|
||||
//| to be raw DEFLATE stream. *bufsize* parameter is for compatibility with
|
||||
//| CPython and is ignored.
|
||||
//|
|
||||
//| :param ~bytes data: data to be decompressed
|
||||
//| :param ~int wbits: DEFLATE dictionary window size used during compression
|
||||
//| :param ~int bufsize: ignored for compatibility with CPython only
|
||||
//| """
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t zlib_decompress(size_t n_args, const mp_obj_t *args) {
|
||||
bool is_zlib = true;
|
||||
if (n_args > 1 && MP_OBJ_SMALL_INT_VALUE(args[1]) < 0) {
|
||||
is_zlib = false;
|
||||
}
|
||||
|
||||
return common_hal_zlib_decompress(args[0], is_zlib);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(zlib_decompress_obj, 1, 3, zlib_decompress);
|
||||
|
||||
STATIC const mp_rom_map_elem_t zlib_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zlib) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&zlib_decompress_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DecompIO), MP_ROM_PTR(&decompio_type) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(zlib_globals, zlib_globals_table);
|
||||
|
||||
const mp_obj_module_t zlib_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t *)&zlib_globals,
|
||||
};
|
||||
|
||||
MP_REGISTER_MODULE(MP_QSTR_zlib, zlib_module, CIRCUITPY_ZLIB);
|
|
@ -24,9 +24,9 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_UZLIB___INIT___H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_UZLIB___INIT___H
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB___INIT___H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB___INIT___H
|
||||
|
||||
mp_obj_t common_hal_uzlib_decompress(mp_obj_t data, bool is_zlib);
|
||||
mp_obj_t common_hal_zlib_decompress(mp_obj_t data, bool is_zlib);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_UZLIB___INIT___H
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB___INIT___H
|
|
@ -37,9 +37,9 @@
|
|||
#include "py/binary.h"
|
||||
#include "py/parsenum.h"
|
||||
|
||||
#include "shared-bindings/uzlib/__init__.h"
|
||||
#include "shared-bindings/uzlib/DecompIO.h"
|
||||
#include "shared-module/uzlib/DecompIO.h"
|
||||
#include "shared-bindings/zlib/__init__.h"
|
||||
#include "shared-bindings/zlib/DecompIO.h"
|
||||
#include "shared-module/zlib/DecompIO.h"
|
||||
|
||||
STATIC int read_src_stream(TINF_DATA *data) {
|
||||
mp_obj_decompio_t *self = (mp_obj_decompio_t *)data->self;
|
||||
|
@ -58,7 +58,7 @@ STATIC int read_src_stream(TINF_DATA *data) {
|
|||
return c;
|
||||
}
|
||||
|
||||
void common_hal_uzlib_decompio_construct(mp_obj_decompio_t *self, mp_obj_t src_stream, mp_int_t dict_opt) {
|
||||
void common_hal_zlib_decompio_construct(mp_obj_decompio_t *self, mp_obj_t src_stream, mp_int_t dict_opt) {
|
||||
self->decomp.self = self;
|
||||
self->decomp.readSource = read_src_stream;
|
||||
self->src_stream = src_stream;
|
||||
|
@ -86,7 +86,7 @@ void common_hal_uzlib_decompio_construct(mp_obj_decompio_t *self, mp_obj_t src_s
|
|||
uzlib_uncompress_init(&self->decomp, m_new(byte, dict_sz), dict_sz);
|
||||
}
|
||||
|
||||
mp_uint_t common_hal_uzlib_decompio_read(mp_obj_decompio_t *self, void *buf, mp_uint_t size, int *errcode) {
|
||||
mp_uint_t common_hal_zlib_decompio_read(mp_obj_decompio_t *self, void *buf, mp_uint_t size, int *errcode) {
|
||||
self->decomp.dest = buf;
|
||||
self->decomp.dest_limit = (unsigned char *)buf + size;
|
||||
int st = uzlib_uncompress_chksum(&self->decomp);
|
|
@ -24,8 +24,8 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SHARED_MODULE_UZLIB_DECOMPIO_H
|
||||
#define SHARED_MODULE_UZLIB_DECOMPIO_H
|
||||
#ifndef SHARED_MODULE_ZLIB_DECOMPIO_H
|
||||
#define SHARED_MODULE_ZLIB_DECOMPIO_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -41,4 +41,4 @@ typedef struct _mp_obj_decompio_t {
|
|||
bool eof;
|
||||
} mp_obj_decompio_t;
|
||||
|
||||
#endif /* SHARED_MODULE_UZLIB_DECOMPIO_H */
|
||||
#endif /* SHARED_MODULE_ZLIB_DECOMPIO_H */
|
|
@ -37,7 +37,7 @@
|
|||
#include "py/binary.h"
|
||||
#include "py/parsenum.h"
|
||||
|
||||
#include "shared-bindings/uzlib/__init__.h"
|
||||
#include "shared-bindings/zlib/__init__.h"
|
||||
|
||||
#define UZLIB_CONF_PARANOID_CHECKS (1)
|
||||
#include "lib/uzlib/tinf.h"
|
||||
|
@ -48,7 +48,7 @@
|
|||
#define DEBUG_printf(...) (void)0
|
||||
#endif
|
||||
|
||||
mp_obj_t common_hal_uzlib_decompress(mp_obj_t data, bool is_zlib) {
|
||||
mp_obj_t common_hal_zlib_decompress(mp_obj_t data, bool is_zlib) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
|
||||
|
||||
|
@ -61,7 +61,7 @@ mp_obj_t common_hal_uzlib_decompress(mp_obj_t data, bool is_zlib) {
|
|||
|
||||
decomp->dest = dest_buf;
|
||||
decomp->dest_limit = dest_buf + dest_buf_size;
|
||||
DEBUG_printf("uzlib: Initial out buffer: " UINT_FMT " bytes\n", decomp->destSize);
|
||||
DEBUG_printf("zlib: Initial out buffer: " UINT_FMT " bytes\n", decomp->destSize);
|
||||
decomp->source = bufinfo.buf;
|
||||
decomp->source_limit = (unsigned char *)bufinfo.buf + bufinfo.len;
|
||||
int st;
|
||||
|
@ -89,7 +89,7 @@ mp_obj_t common_hal_uzlib_decompress(mp_obj_t data, bool is_zlib) {
|
|||
}
|
||||
|
||||
mp_uint_t final_sz = decomp->dest - dest_buf;
|
||||
DEBUG_printf("uzlib: Resizing from " UINT_FMT " to final size: " UINT_FMT " bytes\n", dest_buf_size, final_sz);
|
||||
DEBUG_printf("zlib: Resizing from " UINT_FMT " to final size: " UINT_FMT " bytes\n", dest_buf_size, final_sz);
|
||||
dest_buf = (byte *)m_renew(byte, dest_buf, dest_buf_size, final_sz);
|
||||
mp_obj_t res = mp_obj_new_bytearray_by_ref(final_sz, dest_buf);
|
||||
m_del_obj(TINF_DATA, decomp);
|
Loading…
Reference in New Issue