Last active
December 17, 2024 22:52
-
-
Save obfusk/a644b0190862f45e1eeedd08c1885781 to your computer and use it in GitHub Desktop.
zlib-ng stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
import java.util.zip.Deflater; | |
import java.util.zip.DeflaterOutputStream; | |
public class ZlibNgTest { | |
public static void main(String[] args) { | |
try { | |
String infile = args[0]; | |
String outfile = args[1]; | |
int level = Integer.parseInt(args[2]); | |
int size = Integer.parseInt(args[3]); | |
Deflater deflater = new Deflater(level, true); | |
try (InputStream fins = new FileInputStream(infile); | |
OutputStream fouts = new FileOutputStream(outfile); | |
OutputStream douts = new DeflaterOutputStream(fouts, deflater, 32768)) { | |
byte[] buffer = new byte[size]; | |
int read; | |
while ((read = fins.read(buffer)) != -1) { | |
douts.write(buffer, 0, read); | |
} | |
} | |
} catch (ArrayIndexOutOfBoundsException | IOException e) { | |
System.err.println(e); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys | |
import zlib | |
level, size = map(int, sys.argv[1:]) | |
comp = zlib.compressobj(level, 8, -15) | |
cdata = b"" | |
while True: | |
data = sys.stdin.buffer.read(size) | |
if not data: | |
break | |
cdata += comp.compress(data) | |
cdata += comp.flush() | |
sys.stdout.buffer.write(cdata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment