Skip to content

Commit 6b95b14

Browse files
Added thing for windows without build tools
This is a crappy update that I do not want to release, but there are a lot of people without build tools and not everyone wants to install a large utility
1 parent fdcc531 commit 6b95b14

File tree

11 files changed

+81
-9
lines changed

11 files changed

+81
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### SC Compression
22

3-
Version 0.4.7
3+
Version 0.5.1
44
-
55

66
### Tools:

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.SC, 1)
19+
compress(filedata, Signatures.SCLZ, 1)
2020
)
2121
f.close()

examples/decompressor/test.lzham

1.64 KB
Binary file not shown.

sc_compression.egg-info/PKG-INFO

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Metadata-Version: 2.1
22
Name: sc-compression
3-
Version: 0.4.7
3+
Version: 0.5.1
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.4.7
11+
Version 0.5.1
1212
-
1313

1414
### Tools:

sc_compression.egg-info/SOURCES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ sc_compression/signatures.py
77
sc_compression.egg-info/PKG-INFO
88
sc_compression.egg-info/SOURCES.txt
99
sc_compression.egg-info/dependency_links.txt
10+
sc_compression.egg-info/requires.txt
1011
sc_compression.egg-info/top_level.txt
12+
sc_compression/support/__init__.py
13+
sc_compression/support/lzham.exe
14+
sc_compression/support/lzham.py
1115
sc_compression/utils/__init__.py
1216
sc_compression/utils/reader.py
1317
sc_compression/utils/writer.py

sc_compression/compressor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
try:
88
import lzham
99
except ImportError:
10+
from platform import system as get_system_name
11+
1012
lzham = None
13+
if get_system_name() == 'Windows':
14+
from sc_compression.support.lzham import LZHAM
15+
16+
lzham = LZHAM
1117

1218
try:
1319
import zstandard

sc_compression/decompressor.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
try:
77
import lzham
88
except ImportError:
9+
from platform import system as get_system_name
10+
911
lzham = None
12+
if get_system_name() == 'Windows':
13+
from sc_compression.support.lzham import LZHAM
14+
15+
lzham = LZHAM
1016

1117
try:
1218
import zstandard
@@ -37,10 +43,10 @@ def decompress(self, buffer: bytes) -> bytes:
3743
decompressed = self.decompress(buffer)
3844
elif signature == Signatures.SCLZ:
3945
self.read(4)
40-
if lzham:
41-
dict_size_log2 = self.readUByte()
42-
uncompressed_size = self.readInt32()
46+
dict_size_log2 = self.readUByte()
47+
uncompressed_size = self.readInt32()
4348

49+
if lzham:
4450
filters = {
4551
'dict_size_log2': dict_size_log2
4652
}

sc_compression/support/__init__.py

Whitespace-only changes.

sc_compression/support/lzham.exe

745 KB
Binary file not shown.

sc_compression/support/lzham.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from sc_compression.utils.writer import Writer
2+
from tempfile import mktemp
3+
from os import remove, system, path
4+
5+
6+
class LZHAM:
7+
@staticmethod
8+
def decompress(data, uncompressed_size, filters):
9+
writer = Writer('little')
10+
writer.write(b'LZH\x30')
11+
writer.writeByte(filters['dict_size_log2'])
12+
writer.writeUInt32(uncompressed_size)
13+
writer.writeUInt32(0)
14+
writer.write(data)
15+
16+
temp_file_path = mktemp('.lzham')
17+
with open(temp_file_path, 'wb') as f:
18+
f.write(writer.buffer)
19+
f.close()
20+
21+
if system(f'{path.dirname(__file__)}/lzham.exe '
22+
f'-c -d{filters["dict_size_log2"]} '
23+
f'd {temp_file_path} {temp_file_path} > nul 2>&1'):
24+
return None
25+
with open(temp_file_path, 'rb') as f:
26+
decompressed = f.read()
27+
f.close()
28+
29+
remove(temp_file_path)
30+
31+
return decompressed
32+
33+
@staticmethod
34+
def compress(data, filters):
35+
temp_file_path = mktemp('.data')
36+
with open(temp_file_path, 'wb') as f:
37+
f.write(data)
38+
f.close()
39+
40+
compressed_path = mktemp('.lzham')
41+
if system(f'{path.dirname(__file__)}/lzham.exe '
42+
f'-c -d{filters["dict_size_log2"]} '
43+
f'c {temp_file_path} {compressed_path} > nul 2>&1'):
44+
return None
45+
with open(compressed_path, 'rb') as f:
46+
compressed = f.read()[13:]
47+
f.close()
48+
49+
remove(temp_file_path)
50+
remove(compressed_path)
51+
52+
return compressed

0 commit comments

Comments
 (0)