MCPcopy Index your code
hub / github.com/questdb/questdb / testGzip

Method testGzip

core/src/test/java/io/questdb/test/std/ZipTest.java:48–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46 public final TemporaryFolder temp = new TemporaryFolder();
47
48 @Test
49 public void testGzip() throws Exception {
50 try (Path path = new Path()) {
51 File outFile = temp.newFile("x");
52 File expected = new File(Files.getResourcePath(getClass().getResource("/zip-test/large.csv")));
53
54 final int available = 64 * 1024;
55 long in = Unsafe.malloc(available, MemoryTag.NATIVE_DEFAULT);
56 long out = Unsafe.malloc(available / 2, MemoryTag.NATIVE_DEFAULT);
57 try {
58 long strm = Zip.deflateInit();
59 try {
60
61 long pIn = 0;
62 long pOut = 0;
63 long fdIn = Files.openRO(path.of(expected.getAbsolutePath()).$());
64 try {
65 long fdOut = Files.openRW(path.of(outFile.getAbsolutePath()).$());
66 try {
67 // header
68 Files.write(fdOut, Zip.gzipHeader, Zip.gzipHeaderLen, pOut);
69 pOut += Zip.gzipHeaderLen;
70
71 int len;
72 int crc = 0;
73 while ((len = (int) Files.read(fdIn, in, available, pIn)) > 0) {
74 pIn += len;
75 Zip.setInput(strm, in, len);
76 crc = Zip.crc32(crc, in, len);
77 do {
78 int ret;
79 if ((ret = Zip.deflate(strm, out, available, false)) < 0) {
80 throw new FatalError("Error in deflator: " + ret);
81 }
82
83 int have = available - Zip.availOut(strm);
84 if (have > 0) {
85 Files.write(fdOut, out, have, pOut);
86 pOut += have;
87 }
88
89 } while (Zip.availIn(strm) > 0);
90 }
91
92 int ret;
93 do {
94 if ((ret = Zip.deflate(strm, out, available, true)) < 0) {
95 throw new FatalError("Error in deflator: " + ret);
96 }
97
98 int have = available - Zip.availOut(strm);
99 if (have > 0) {
100 Files.write(fdOut, out, have, pOut);
101 pOut += have;
102 }
103 } while (ret != 1);
104
105 // write trailer

Callers

nothing calls this directly

Calls 15

getResourcePathMethod · 0.95
mallocMethod · 0.95
deflateInitMethod · 0.95
openROMethod · 0.95
openRWMethod · 0.95
writeMethod · 0.95
readMethod · 0.95
setInputMethod · 0.95
crc32Method · 0.95
deflateMethod · 0.95
availOutMethod · 0.95
availInMethod · 0.95

Tested by

no test coverage detected