Skip to content

Commit 17f950b

Browse files
committed
Move the selection between the native and Python implementations of lzo and lz4 to dissect.util
1 parent a28fea9 commit 17f950b

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ Information on the supported Python versions can be found in the Getting Started
1717
pip install dissect.squashfs
1818
```
1919

20-
This module is also automatically installed if you install the `dissect` package.
20+
This project decompresses lzo and lz4 compressed file systems and can use the faster, native (C-based) lz4 and lzo
21+
implementations when installed, instead of the slower pure Python implementation provided by `dissect.util`. To use
22+
these faster implementations, install the package with the lzo and lz4 extras:
23+
24+
```bash
25+
pip install "dissect.squashfs[lz4,lzo]"
26+
```
27+
28+
Unfortunately there is no binary python-lzo wheel for PyPy installations on Windows, so it won't be installed there
29+
30+
This module including the lz4 and lzo extras is also automatically installed if you install the `dissect` package.
2131

2232
## Build and test instructions
2333

dissect/squashfs/compression.py

+5-19
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ def initialize(id: int, options: Optional[bytes]) -> Compression:
1111
modules = {
1212
c_squashfs.ZLIB_COMPRESSION: (NativeZlib,),
1313
c_squashfs.LZMA_COMPRESSION: (NativeLZMA,),
14-
c_squashfs.LZO_COMPRESSION: (NativeLZO, PythonLZO),
14+
c_squashfs.LZO_COMPRESSION: (AvailableLZO,),
1515
c_squashfs.XZ_COMPRESSION: (NativeXZ,),
16-
c_squashfs.LZ4_COMPRESSION: (NativeLZ4, PythonLZ4),
16+
c_squashfs.LZ4_COMPRESSION: (AvailableLZ4,),
1717
c_squashfs.ZSTD_COMPRESSION: (NativeZSTD,),
1818
}
1919

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

6262

63-
class NativeLZO(Compression):
64-
module = "lzo"
65-
66-
def decompress(self, data: bytes, expected: int) -> bytes:
67-
return self._module.decompress(data, False, expected)
68-
69-
70-
class PythonLZO(Compression):
63+
class AvailableLZO(Compression):
7164
module = "dissect.util.compression.lzo"
7265

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

8376

84-
class NativeLZ4(Compression):
85-
module = "lz4.block"
86-
87-
def decompress(self, data: bytes, expected: int) -> bytes:
88-
return self._module.decompress(data, expected)
89-
90-
91-
class PythonLZ4(Compression):
77+
class AvailableLZ4(Compression):
9278
module = "dissect.util.compression.lz4"
9379

9480
def decompress(self, data: bytes, expected: int) -> bytes:
95-
return self._module.decompress(data)
81+
return self._module.decompress(data, uncompressed_size=expected)
9682

9783

9884
class NativeZSTD(Compression):

pyproject.toml

-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ repository = "https://github.com/fox-it/dissect.squashfs"
3737

3838
[project.optional-dependencies]
3939
full = [
40-
"lz4",
41-
# There are no Windows PyPy wheels available for python-lzo
42-
# So we use a pure python fallback for it.
43-
"python-lzo; platform_system != 'Windows' or platform_python_implementation != 'PyPy'",
4440
"zstandard",
4541
]
4642
dev = [

0 commit comments

Comments
 (0)