Skip to content

Commit

Permalink
Move the selection between the native and Python implementations of l…
Browse files Browse the repository at this point in the history
…zo and lz4 to dissect.util
  • Loading branch information
pyrco committed Jul 25, 2024
1 parent a28fea9 commit 17f950b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ Information on the supported Python versions can be found in the Getting Started
pip install dissect.squashfs
```

This module is also automatically installed if you install the `dissect` package.
This project decompresses lzo and lz4 compressed file systems and can use the faster, native (C-based) lz4 and lzo
implementations when installed, instead of the slower pure Python implementation provided by `dissect.util`. To use
these faster implementations, install the package with the lzo and lz4 extras:

```bash
pip install "dissect.squashfs[lz4,lzo]"
```

Unfortunately there is no binary python-lzo wheel for PyPy installations on Windows, so it won't be installed there

This module including the lz4 and lzo extras is also automatically installed if you install the `dissect` package.

## Build and test instructions

Expand Down
24 changes: 5 additions & 19 deletions dissect/squashfs/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def initialize(id: int, options: Optional[bytes]) -> Compression:
modules = {
c_squashfs.ZLIB_COMPRESSION: (NativeZlib,),
c_squashfs.LZMA_COMPRESSION: (NativeLZMA,),
c_squashfs.LZO_COMPRESSION: (NativeLZO, PythonLZO),
c_squashfs.LZO_COMPRESSION: (AvailableLZO,),
c_squashfs.XZ_COMPRESSION: (NativeXZ,),
c_squashfs.LZ4_COMPRESSION: (NativeLZ4, PythonLZ4),
c_squashfs.LZ4_COMPRESSION: (AvailableLZ4,),
c_squashfs.ZSTD_COMPRESSION: (NativeZSTD,),
}

Expand Down Expand Up @@ -60,14 +60,7 @@ def decompress(self, data: bytes, expected: int) -> bytes:
return self._module.decompress(data)


class NativeLZO(Compression):
module = "lzo"

def decompress(self, data: bytes, expected: int) -> bytes:
return self._module.decompress(data, False, expected)


class PythonLZO(Compression):
class AvailableLZO(Compression):
module = "dissect.util.compression.lzo"

def decompress(self, data: bytes, expected: int) -> bytes:
Expand All @@ -81,18 +74,11 @@ def decompress(self, data: bytes, expected: int) -> bytes:
return self._module.decompress(data)


class NativeLZ4(Compression):
module = "lz4.block"

def decompress(self, data: bytes, expected: int) -> bytes:
return self._module.decompress(data, expected)


class PythonLZ4(Compression):
class AvailableLZ4(Compression):
module = "dissect.util.compression.lz4"

def decompress(self, data: bytes, expected: int) -> bytes:
return self._module.decompress(data)
return self._module.decompress(data, uncompressed_size=expected)


class NativeZSTD(Compression):
Expand Down
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ repository = "https://github.com/fox-it/dissect.squashfs"

[project.optional-dependencies]
full = [
"lz4",
# There are no Windows PyPy wheels available for python-lzo
# So we use a pure python fallback for it.
"python-lzo; platform_system != 'Windows' or platform_python_implementation != 'PyPy'",
"zstandard",
]
dev = [
Expand Down

0 comments on commit 17f950b

Please sign in to comment.