diff --git a/src/msglc/config.py b/src/msglc/config.py index 1110122..734c935 100644 --- a/src/msglc/config.py +++ b/src/msglc/config.py @@ -62,6 +62,34 @@ def configure( """ This function is used to configure the settings. It accepts any number of keyword arguments. The function updates the values of the configuration parameters if they are provided in the arguments. + + :param small_obj_optimization_threshold: + The threshold (in bytes) for small object optimization. + Objects smaller than this threshold are not indexed. + :param write_buffer_size: + The size (in bytes) for the write buffer. + :param read_buffer_size: + The size (in bytes) for the read buffer. + :param fast_loading: + Flag to enable or disable fast loading. + If enabled, the container will be read in one go, instead of reading each child separately. + :param fast_loading_threshold: + The threshold (0 to 1) for fast loading. + With the fast loading flag turned on, fast loading will be performed if the number of + already read children over the total number of children is smaller than this threshold. + :param trivial_size: + The size (in bytes) considered trivial, around a dozen bytes. + Objects smaller than this size are considered trivial. + For a list of trivial objects, the container will be indexed in a blocked fashion. + :param disable_gc: + Flag to enable or disable garbage collection. + :param simple_repr: + Flag to enable or disable simple representation used in the __repr__ method. + If turned on, __repr__ will not incur any disk I/O. + :param copy_chunk_size: + The size (in bytes) for the copy chunk. + :param magic: + Magic bytes (max length: 30) to set, used to identify the file format version. """ if ( isinstance(small_obj_optimization_threshold, int) diff --git a/src/msglc/reader.py b/src/msglc/reader.py index 8e42f89..42c6328 100644 --- a/src/msglc/reader.py +++ b/src/msglc/reader.py @@ -427,6 +427,21 @@ def __init__( unpacker: Unpacker | None = None, ): """ + It is possible to use a customized unpacker. + Please inherit the `Unpacker` class from the `unpacker.py`. + There are already several unpackers available using different libraries. + + .. highlight:: python + .. code-block:: python + class CustomUnpacker(Unpacker): + def decode(self, data: bytes): + # provide the decoding logic + ... + + with LazyReader("file.msg", unpacker=CustomUnpacker()) as reader: + # read the data + ... + :param buffer_or_path: the buffer or path to the file :param counter: the counter object for tracking the number of bytes read :param cached: whether to cache the data diff --git a/src/msglc/generate.py b/tests/generate.py similarity index 100% rename from src/msglc/generate.py rename to tests/generate.py diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index 5007ec3..62a3247 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -18,7 +18,7 @@ import pytest from msglc import dump, config -from msglc.generate import ( +from generate import ( generate_random_json, find_all_paths, goto_path,