Skip to content

Commit 9cb5ba7

Browse files
New version (4)
1 parent 6b95b14 commit 9cb5ba7

File tree

11 files changed

+29
-24
lines changed

11 files changed

+29
-24
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
### SC Compression
22

3-
Version 0.5.1
3+
Version 0.5.6
44
-
55

66
### Tools:
7-
- Decompression
8-
- Compression
7+
- Decompressor
8+
- Compressor
99

1010
### Supported compressions:
1111
- LZMA

examples/compressor/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
f.close()
1717
with open('out/' + filename, 'wb') as f:
1818
f.write(
19-
compress(filedata, Signatures.SCLZ, 1)
19+
compress(filedata, Signatures.SC, 4)
2020
)
2121
f.close()

examples/decompressor/test.lzham

-1.64 KB
Binary file not shown.

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
zstandard
2-
pylzham

sc_compression.egg-info/PKG-INFO

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
Metadata-Version: 2.1
22
Name: sc-compression
3-
Version: 0.5.1
3+
Version: 0.5.6
44
Summary: SC Compression
55
Home-page: https://github.com/vorono4ka/sc-compression
66
Author: Vorono4ka
77
Author-email: [email protected]
88
License: GPLv3
99
Description: ### SC Compression
1010

11-
Version 0.5.1
11+
Version 0.5.6
1212
-
1313

1414
### Tools:
15-
- Decompression
16-
- Compression
15+
- Decompressor
16+
- Compressor
1717

1818
### Supported compressions:
1919
- LZMA

sc_compression.egg-info/SOURCES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
LICENSE
12
README.md
23
setup.py
34
sc_compression/__init__.py

sc_compression/compressor.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def compress(self, data, signature: int, file_version: int = None) -> bytes:
4343
uncompressed_size = len(data)
4444

4545
if file_version is None:
46-
file_version = 2 if zstandard and not (Signatures.SCLZ & signature) else 1
46+
file_version = 3 if zstandard and not (Signatures.SCLZ & signature) else 1
4747

4848
if Signatures.ZSTD & signature and not zstandard or \
4949
Signatures.SCLZ & signature and not lzham:
@@ -52,7 +52,7 @@ def compress(self, data, signature: int, file_version: int = None) -> bytes:
5252
super().__init__('little')
5353
if signature is Signatures.NONE:
5454
return data
55-
elif ((Signatures.LZMA | Signatures.SIG) & signature) or (Signatures.SC & signature and file_version != 2):
55+
elif ((Signatures.LZMA | Signatures.SIG) & signature) or (Signatures.SC & signature and file_version != 3):
5656
compressed = lzma.compress(data, format=lzma.FORMAT_ALONE, filters=self.lzma_filters)
5757

5858
self.write(compressed[:5])
@@ -71,20 +71,23 @@ def compress(self, data, signature: int, file_version: int = None) -> bytes:
7171
self.write(compressed)
7272

7373
compressed = self.buffer
74-
elif (Signatures.SC | Signatures.ZSTD) & signature and file_version == 2:
74+
elif (Signatures.SC | Signatures.ZSTD) & signature and file_version == 3:
7575
compressor = zstandard.ZstdCompressor()
7676
compressed = compressor.compress(data)
7777
else:
7878
raise TypeError('Unknown Signature!')
7979

8080
super().__init__('big')
8181
if (Signatures.SC | Signatures.SCLZ) & signature:
82-
data_hash = md5(data)
82+
data_hash = md5(data).digest()
8383

8484
self.write(b'SC')
8585
self.writeInt32(file_version)
86-
self.writeInt32(16)
87-
compressed = self.buffer + data_hash.digest() + compressed
86+
if file_version == 4:
87+
self.writeInt32(1)
88+
self.writeInt32(len(data_hash))
89+
self.write(data_hash)
90+
compressed = self.buffer + compressed
8891
elif signature == Signatures.SIG:
8992
self.write(b'Sig:')
9093
self.write(b'\x00' * 64) # sha64

sc_compression/decompressor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ def decompress(self, buffer: bytes) -> bytes:
3232

3333
decompressed = buffer
3434
signature = self.signatures.get_signature(self.buffer, self.file_version)
35+
if signature == Signatures.NONE:
36+
return decompressed
37+
3538
if signature == Signatures.SC:
3639
super().__init__(buffer, 'big')
3740
self.read(2)
3841
self.file_version = self.readInt32()
42+
if self.file_version >= 4:
43+
self.file_version = self.readInt32()
3944
self.hash = self.read(self.readInt32())
40-
decompressed = self.decompress(buffer[26:])
45+
decompressed = self.decompress(buffer[self.i:])
4146
elif signature == Signatures.SIG:
4247
buffer = buffer[68:]
4348
decompressed = self.decompress(buffer)

sc_compression/signatures.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ def __init__(self):
1414

1515
def get_signature(self, buffer, file_version: int = -1) -> int:
1616
signature = Signatures.NONE
17-
if self.last_signature == Signatures.SC and file_version == 1:
18-
signature = Signatures.LZMA
19-
self.last_signature = -1
20-
elif self.last_signature == Signatures.SC and file_version == 2:
21-
signature = Signatures.ZSTD
22-
self.last_signature = -1
2317

2418
if re.match(b'\x00\x00?\x00', buffer[1:5]):
2519
signature = Signatures.LZMA
20+
elif file_version >= 2 and buffer.startswith(b'\x28\xb5\x2f\xfd'):
21+
signature = Signatures.ZSTD
22+
2623
if buffer.startswith(b'SCLZ'):
2724
signature = Signatures.SCLZ
2825
elif buffer.startswith(b'SC'):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setuptools.setup(
1212
name='sc-compression',
13-
version='0.5.1',
13+
version='0.5.6',
1414
author='Vorono4ka',
1515
author_email='[email protected]',
1616
description='SC Compression',

0 commit comments

Comments
 (0)