Skip to content

Commit

Permalink
#103 Avoid array when ECD
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-cherednik committed Nov 23, 2024
1 parent 66bf184 commit 5662ea0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static DataInput create(ZipEntry zipEntry,
if (compressionMethod == CompressionMethod.LZMA)
return new LzmaEntryDataInput(zipEntry, in);
if (compressionMethod == CompressionMethod.ZSTD)
return new ZstdEntryDataInput(zipEntry, in);
return new ZstdEntryDataInput(in);

throw new CompressionNotSupportedException(compressionMethod);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import ru.olegcherednik.zip4jvm.io.in.data.DataInput;
import ru.olegcherednik.zip4jvm.io.zstd.ZstdInputStream;
import ru.olegcherednik.zip4jvm.model.entry.ZipEntry;

import org.apache.commons.io.IOUtils;

Expand All @@ -34,9 +33,9 @@ final class ZstdEntryDataInput extends CompressedEntryDataInput {

private final ZstdInputStream zstd;

ZstdEntryDataInput(ZipEntry zipEntry, DataInput in) {
ZstdEntryDataInput(DataInput in) {
super(in);
zstd = new ZstdInputStream(in, zipEntry.getUncompressedSize());
zstd = new ZstdInputStream(in);
}

// ---------- ReadBuffer ----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ public class ZstdInputStream extends InputStream {

private final com.github.luben.zstd.ZstdInputStream zstd;
private final byte[] buf = new byte[1];
private long bytesToRead;

public ZstdInputStream(DataInput in, long uncompressedSize) {
public ZstdInputStream(DataInput in) {
try {
zstd = new com.github.luben.zstd.ZstdInputStream(new Decorator(in));
bytesToRead = uncompressedSize;
} catch (IOException e) {
throw new Zip4jvmException(e);
}
Expand All @@ -55,15 +53,7 @@ public int read() throws IOException {

@Override
public int read(byte[] buf, int offs, int len) throws IOException {
if (bytesToRead <= 0) {
// TODO I do not know why we do this
// in.seek(finalAbsoluteOffs);
return IOUtils.EOF;
}

int total = zstd.read(buf, offs, len);
bytesToRead -= total;
return total;
return zstd.read(buf, offs, len);
}

@RequiredArgsConstructor
Expand Down

0 comments on commit 5662ea0

Please sign in to comment.