teavm
teavm copied to clipboard
ZipFile doesn't chunk entries correctly
Noticed this when trying to read zip entries by their declared size:
try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream("test.zip"))) {
zip.putNextEntry(new ZipEntry("example"));
byte[] in = new byte[3000]; //Just something bigger than the 2048 buffer TInputStream uses
Arrays.fill(in, (byte) 1);
zip.write(in);
}
try (ZipFile zip = new ZipFile("test.zip")) {
ZipEntry entry = zip.getEntry("example");
byte[] read;
try (InputStream in = zip.getInputStream(entry)) {
read = stream.readNBytes((int) entry.getSize());
}
assert read.length == 3000;
}
When run as JavaScript at least, I get the following crash....
Exception in thread "main" java.io.EOFException
at org.teavm.classlib.java.util.zip.TInflaterInputStream.read(TInflaterInputStream.java:106)
at org.teavm.classlib.java.util.zip.TZipFile$ZipInflaterInputStream.read(TZipFile.java:331)
at org.teavm.classlib.java.io.TInputStream.readNBytes(TInputStream.java:108)
at com.chocohead.Example.main(Example.java:46)
Interestingly enough, using a ZipInputStream
works fine:
try (ZipInputStream zip = new ZipInputStream(new FileInputStream("test.zip"))) {
zip.getNextEntry();
byte[] read = zip.readNBytes(3000);
assert read.length == 3000;
}