binpickle
Advanced tools
| # Changes here will be overwritten by Copier | ||
| _commit: 8d75d6c | ||
| _commit: 00050f1 | ||
| _src_path: https://github.com/lenskit/lk-project-template | ||
@@ -4,0 +4,0 @@ package_name: binpickle |
@@ -72,3 +72,3 @@ name: Validate Source Rules | ||
| env: | ||
| FMT_PASSED: ${{ steps.fmt.outputs.passed }} | ||
| FMT_PASSED: ${{ steps.format.outputs.passed }} | ||
| LINT_PASSED: ${{ steps.lint.outputs.passed }} | ||
@@ -75,0 +75,0 @@ LINT_REQUIRED: True |
@@ -33,3 +33,3 @@ name: Test and Package | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
@@ -61,3 +61,3 @@ fetch-depth: 0 | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
@@ -83,3 +83,3 @@ fetch-depth: 0 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v2 | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
@@ -89,3 +89,3 @@ python-version: "3.10" | ||
| - name: Install Python deps | ||
| run: pip install -U build | ||
| run: pip install -U build twine | ||
@@ -92,0 +92,0 @@ - name: Build distribution |
@@ -5,3 +5,3 @@ { | ||
| "editor.codeActionsOnSave": { | ||
| "source.organizeImports": true | ||
| "source.organizeImports": "explicit" | ||
| }, | ||
@@ -8,0 +8,0 @@ "editor.formatOnSave": true, |
| Metadata-Version: 2.1 | ||
| Name: binpickle | ||
| Version: 0.4.0a2 | ||
| Version: 0.4.0a3 | ||
| Summary: Optimized format for pickling binary data. | ||
@@ -5,0 +5,0 @@ Author-email: Michael Ekstrand <mdekstrand@drexel.edu> |
+20
-2
@@ -78,3 +78,12 @@ """ | ||
| def decode(cls, buf: bytes | bytearray | memoryview, *, verify: bool = True) -> FileHeader: | ||
| "Decode a file header from bytes." | ||
| """ | ||
| Decode a file header from bytes. | ||
| Args: | ||
| buf: | ||
| Buffer contianing the file header to decode. | ||
| verify: | ||
| Whether to fail on invalid header data (such as mismatched magic | ||
| or unsupported version). | ||
| """ | ||
| if len(buf) != HEADER_FORMAT.size: | ||
@@ -124,4 +133,7 @@ raise FormatError("incorrect header length") | ||
| offset: int | ||
| "Position of the start of the file index." | ||
| length: int | ||
| "Length of the file index." | ||
| hash: bytes | ||
| "SHA-256 digest of the file index." | ||
@@ -134,3 +146,9 @@ def encode(self): | ||
| def decode(cls, buf: bytes | bytearray | memoryview, *, verify: bool = True) -> FileTrailer: | ||
| "Decode a file trailer from bytes." | ||
| """ | ||
| Decode a file trailer from bytes. | ||
| Args: | ||
| buf: Buffer containing the trailer to decode. | ||
| verify: Whether to verify invalid trailer data (currently ignored). | ||
| """ | ||
| off, len, ck = TRAILER_FORMAT.unpack(buf) | ||
@@ -137,0 +155,0 @@ return cls(off, len, ck) |
@@ -46,5 +46,5 @@ import hashlib | ||
| Args: | ||
| filename(str or pathlib.Path): | ||
| filename: | ||
| The name of the file to load. | ||
| direct(bool or str): | ||
| direct: | ||
| If ``True``, returned objects zero-copy when possible, but cannot | ||
@@ -55,3 +55,3 @@ outlast the :class:`BinPickleFile` instance. If ``False``, they | ||
| direct mode but do not warn if the file is unmappable. | ||
| verify(bool): | ||
| verify: | ||
| If ``True`` (the default), verify file checksums while reading. | ||
@@ -232,3 +232,3 @@ """ | ||
| Args: | ||
| file(str or pathlib.Path): The file to load. | ||
| file: The file to load. | ||
| """ | ||
@@ -244,2 +244,5 @@ | ||
| about it. | ||
| Args: | ||
| file: the path to the file to test. | ||
| """ | ||
@@ -246,0 +249,0 @@ try: |
+18
-12
@@ -31,3 +31,3 @@ import hashlib | ||
| class BinPickler: | ||
| class BinPickler(pickle.Pickler): | ||
| """ | ||
@@ -42,8 +42,11 @@ Save an object into a binary pickle file. This is like :class:`pickle.Pickler`, | ||
| Only one object can be dumped to a `BinPickler`. Other methods are exposed | ||
| for manually constructing BinPickle files but their use is highly discouraged. | ||
| Args: | ||
| filename(str or pathlib.Path): | ||
| filename: | ||
| The path to the file to write. | ||
| align(bool): | ||
| align: | ||
| If ``True``, align buffers to the page size. | ||
| codecs(list of CodecArg): | ||
| codecs: | ||
| The list of codecs to use for encoding buffers. The codecs are | ||
@@ -63,2 +66,3 @@ applied in sequence to encode a buffer, and in reverse order to | ||
| _pickle_stream: io.BytesIO | ||
| filename: str | PathLike[str] | ||
@@ -77,2 +81,3 @@ align: bool | ||
| ): | ||
| self._pickle_stream = io.BytesIO() | ||
| self.filename = filename | ||
@@ -83,2 +88,7 @@ self.align = align | ||
| # set up the binpickler | ||
| super().__init__( | ||
| self._pickle_stream, pickle.HIGHEST_PROTOCOL, buffer_callback=self._write_buffer | ||
| ) | ||
| if codecs is None: | ||
@@ -104,8 +114,4 @@ self.codecs = [] | ||
| "Dump an object to the file. Can only be called once." | ||
| bio = io.BytesIO() | ||
| pk = pickle.Pickler( | ||
| bio, protocol=pickle.HIGHEST_PROTOCOL, buffer_callback=self._write_buffer | ||
| ) | ||
| pk.dump(obj) | ||
| buf = bio.getbuffer() | ||
| super().dump(obj) | ||
| buf = self._pickle_stream.getbuffer() | ||
@@ -247,4 +253,4 @@ tot_enc = sum(e.enc_length for e in self.entries) | ||
| obj: The object to dump. | ||
| file(str or pathlib.Path): The file in which to save the object. | ||
| mappable(bool): | ||
| file: The file in which to save the object. | ||
| mappable: | ||
| If ``True``, save for memory-mapping. ``codec`` is ignored | ||
@@ -251,0 +257,0 @@ in this case. |
+2
-1
@@ -34,3 +34,3 @@ import os | ||
| "numpy": ("https://docs.scipy.org/doc/numpy/", None), | ||
| "sklearn": ("https://scikit-learn.org/stable/", None), | ||
| "numcodecs": ("https://numcodecs.readthedocs.io/en/stable/", None), | ||
| } | ||
@@ -42,1 +42,2 @@ | ||
| } | ||
| autodoc_typehints = "description" |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: binpickle | ||
| Version: 0.4.0a2 | ||
| Version: 0.4.0a3 | ||
| Summary: Optimized format for pickling binary data. | ||
@@ -5,0 +5,0 @@ Author-email: Michael Ekstrand <mdekstrand@drexel.edu> |
+2
-1
@@ -90,2 +90,3 @@ [build-system] | ||
| "third-party", | ||
| "testing", | ||
| "first-party", | ||
@@ -96,3 +97,3 @@ "local-folder", | ||
| [tool.ruff.lint.isort.sections] | ||
| test = ["pytest", "hypothesis"] | ||
| testing = ["pytest", "hypothesis"] | ||
@@ -99,0 +100,0 @@ [tool.mypy] |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
67029
1.26%1071
2.19%