Skip to content

Commit f9e5b43

Browse files
committed
Compress argon2.wasm
1 parent 5055ed2 commit f9e5b43

File tree

6 files changed

+69
-3
lines changed

6 files changed

+69
-3
lines changed

JetStreamDriver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,7 @@ let BENCHMARKS = [
23782378
"./wasm/argon2/benchmark.js",
23792379
],
23802380
preload: {
2381-
wasmBinary: "./wasm/argon2/build/argon2.wasm",
2381+
wasmBinary: "./wasm/argon2/build/argon2.wasm.z",
23822382
},
23832383
iterations: 30,
23842384
worstCaseCount: 3,

compress.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import zlib
2+
import argparse
3+
import sys
4+
import os
5+
6+
def compress_file(input_path, output_path, remove_input=False):
7+
"""Compress a file using zlib compression."""
8+
try:
9+
# Read input file in binary mode
10+
with open(input_path, 'rb') as input_file:
11+
data = input_file.read()
12+
13+
# Compress the data
14+
compressed_data = zlib.compress(data)
15+
16+
# Write compressed data to output file
17+
with open(output_path, 'wb') as output_file:
18+
output_file.write(compressed_data)
19+
20+
# Print compression statistics
21+
original_size = len(data)
22+
compressed_size = len(compressed_data)
23+
compression_ratio = (1 - compressed_size / original_size) * 100
24+
25+
print(f"Compression complete!")
26+
print(f"Original size: {original_size} bytes")
27+
print(f"Compressed size: {compressed_size} bytes")
28+
print(f"Compression ratio: {compression_ratio:.2f}%")
29+
30+
# Remove input file if requested
31+
if remove_input:
32+
os.remove(input_path)
33+
print(f"Input file '{input_path}' deleted.")
34+
35+
except FileNotFoundError:
36+
print(f"Error: Input file '{input_path}' not found.", file=sys.stderr)
37+
sys.exit(1)
38+
except PermissionError:
39+
print(f"Error: Permission denied accessing files.", file=sys.stderr)
40+
sys.exit(1)
41+
except Exception as e:
42+
print(f"Error: {e}", file=sys.stderr)
43+
sys.exit(1)
44+
45+
def main():
46+
parser = argparse.ArgumentParser(description="Compress a file using zlib compression")
47+
parser.add_argument("input_file", help="Path to the input file to compress")
48+
parser.add_argument("output_file", nargs='?', help="Path to the output compressed file (default: input_file + '.z')")
49+
parser.add_argument("--rm", action="store_true", help="Remove input file after successful compression")
50+
51+
args = parser.parse_args()
52+
53+
# Check if input file exists
54+
if not os.path.exists(args.input_file):
55+
print(f"Error: Input file '{args.input_file}' does not exist.", file=sys.stderr)
56+
sys.exit(1)
57+
58+
# Generate output filename if not provided
59+
output_file = args.output_file if args.output_file else args.input_file + '.z'
60+
61+
compress_file(args.input_file, output_file, args.rm)
62+
63+
if __name__ == "__main__":
64+
main()

wasm/argon2/build.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Built on 2025-02-11T16:03:39Z
1+
Built on 2025-08-29T16:00:22Z
22
Toolchain versions
3-
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.0-git
3+
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.0 (97c7c2adab1791b9487d1f376934a3bdc28f8a67)
44
Building...
55
Building done

wasm/argon2/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ emcc -o build/argon2.js \
3939
-Iinclude \
4040
${SOURCES[@]} | tee -a "$BUILD_LOG"
4141

42+
python3 ../../compress.py --rm ./build/argon2.wasm
43+
4244
echo "Building done" | tee -a "$BUILD_LOG"
4345
ls -lth build/

wasm/argon2/build/argon2.wasm

-30.2 KB
Binary file not shown.

wasm/argon2/build/argon2.wasm.z

12.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)