Skip to content

Instantly share code, notes, and snippets.

@obfusk
Last active December 17, 2024 22:52
Show Gist options
  • Save obfusk/a644b0190862f45e1eeedd08c1885781 to your computer and use it in GitHub Desktop.
Save obfusk/a644b0190862f45e1eeedd08c1885781 to your computer and use it in GitHub Desktop.
zlib-ng stuff
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);
}
}
}
#!/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