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 (#27)
  • Loading branch information
pyrco authored Jul 29, 2024
1 parent a28fea9 commit d021f6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 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
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ repository = "https://github.com/fox-it/dissect.squashfs"

[project.optional-dependencies]
full = [
"lz4",
"zstandard",
]
lzo = [
# 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",
]
lz4 = [
"lz4",
]
dev = [
"dissect.squashfs[full]",
Expand Down

0 comments on commit d021f6b

Please sign in to comment.