Skip to content

Commit 21df014

Browse files
lzham decompressing with binary fix
1 parent aee1875 commit 21df014

File tree

6 files changed

+34
-31
lines changed

6 files changed

+34
-31
lines changed

.gitignore

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
sc_compression.egg-info/
2-
examples/decompressor/out/
3-
examples/decompressor/in/
4-
examples/compressor/out/
5-
examples/compressor/in/
6-
.idea/
7-
build/
8-
dist/
1+
# IDE project directories
2+
/.idea/
3+
4+
# Setuptools directories
5+
/sc_compression.egg-info/
6+
/build/
7+
/dist/
8+
9+
# Scripts directories
10+
/examples/**/out/
11+
/examples/**/in/
12+
13+
# Python compiled files
914
*.pyc

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.6.0
3+
Version 0.6.1
44
-
55

66
### Tools:

examples/compressor/main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
for filename in os.listdir('in'):
1414
with open('in/' + filename, 'rb') as f:
15-
filedata = f.read()
15+
file_data = f.read()
1616
f.close()
1717
with open('out/' + filename, 'wb') as f:
18-
f.write(
19-
compress(filedata, Signatures.SC, 3)
20-
)
18+
f.write(compress(file_data, Signatures.SC, 3))
2119
f.close()

examples/decompressor/main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111

1212
for filename in os.listdir('in'):
1313
with open('in/' + filename, 'rb') as f:
14-
filedata = f.read()
14+
file_data = f.read()
1515
f.close()
1616
with open('out/' + filename, 'wb') as f:
17-
f.write(
18-
decompress(filedata)[0]
19-
)
17+
f.write(decompress(file_data)[0])
2018
f.close()

sc_compression/support/lzham.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,39 @@ def decompress(data, uncompressed_size, filters):
1414
writer.write(data)
1515

1616
temp_file_path = mktemp('.lzham')
17-
with open(temp_file_path, 'wb') as f:
18-
f.write(writer.buffer)
19-
f.close()
17+
with open(temp_file_path, 'wb') as file:
18+
file.write(writer.buffer)
2019

20+
decompressed_path = mktemp('.lzham')
2121
if system(f'{path.dirname(__file__)}/lzham.exe '
2222
f'-c -d{filters["dict_size_log2"]} '
23-
f'd {temp_file_path} {temp_file_path} > nul 2>&1'):
23+
f'd {temp_file_path} {decompressed_path} > nul 2>&1'):
24+
remove(temp_file_path)
25+
remove(decompressed_path)
2426
return None
25-
with open(temp_file_path, 'rb') as f:
26-
decompressed = f.read()
27-
f.close()
27+
with open(decompressed_path, 'rb') as file:
28+
decompressed = file.read()
2829

2930
remove(temp_file_path)
31+
remove(decompressed_path)
3032

3133
return decompressed
3234

3335
@staticmethod
3436
def compress(data, filters):
3537
temp_file_path = mktemp('.data')
36-
with open(temp_file_path, 'wb') as f:
37-
f.write(data)
38-
f.close()
38+
with open(temp_file_path, 'wb') as file:
39+
file.write(data)
3940

4041
compressed_path = mktemp('.lzham')
4142
if system(f'{path.dirname(__file__)}/lzham.exe '
4243
f'-c -d{filters["dict_size_log2"]} '
4344
f'c {temp_file_path} {compressed_path} > nul 2>&1'):
45+
remove(temp_file_path)
46+
remove(compressed_path)
4447
return None
45-
with open(compressed_path, 'rb') as f:
46-
compressed = f.read()[13:]
47-
f.close()
48+
with open(compressed_path, 'rb') as file:
49+
compressed = file.read()[13:]
4850

4951
remove(temp_file_path)
5052
remove(compressed_path)

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.6.0',
13+
version='0.6.1',
1414
author='Vorono4ka',
1515
author_email='crowo4ka@gmail.com',
1616
description='SC Compression',

0 commit comments

Comments
 (0)