Skip to content

Commit

Permalink
COMPRESS-437 add read-only DEFLATE64 support to 7z
Browse files Browse the repository at this point in the history
  • Loading branch information
bodewig committed Jan 13, 2018
1 parent 5b004bf commit 738c708
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ The <action> type attribute can be add,update,fix,remove.
due-to="Dawid Weiss">
Speed improvement for DEFLATE64 decompression.
</action>
<action issue="COMPRESS-437" type="add" date="2018-01-13">
Added read-only DEFLATE64 support to 7z archives.
</action>
</release>
<release version="1.15" date="2017-10-17"
description="Release 1.15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
import org.apache.commons.compress.compressors.deflate64.Deflate64CompressorInputStream;
import org.apache.commons.compress.utils.FlushShieldFilterOutputStream;
import org.tukaani.xz.ARMOptions;
import org.tukaani.xz.ARMThumbOptions;
Expand All @@ -50,6 +51,7 @@ class Coders {
put(SevenZMethod.LZMA, new LZMADecoder());
put(SevenZMethod.LZMA2, new LZMA2Decoder());
put(SevenZMethod.DEFLATE, new DeflateDecoder());
put(SevenZMethod.DEFLATE64, new Deflate64Decoder());
put(SevenZMethod.BZIP2, new BZIP2Decoder());
put(SevenZMethod.AES256SHA256, new AES256SHA256Decoder());
put(SevenZMethod.BCJ_X86_FILTER, new BCJDecoder(new X86Options()));
Expand Down Expand Up @@ -219,6 +221,20 @@ public void close() throws IOException {
}
}

static class Deflate64Decoder extends CoderBase {
Deflate64Decoder() {
super(Number.class);
}

@SuppressWarnings("resource") // caller must close the InputStream
@Override
InputStream decode(final String archiveName, final InputStream in, final long uncompressedLength,
final Coder coder, final byte[] password)
throws IOException {
return new Deflate64CompressorInputStream(in);
}
}

static class BZIP2Decoder extends CoderBase {
BZIP2Decoder() {
super(Number.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public enum SevenZMethod {
LZMA2(new byte[] { (byte)0x21 }),
/** Deflate */
DEFLATE(new byte[] { (byte)0x04, (byte)0x01, (byte)0x08 }),
/**
* Deflate64
* @since 1.16
*/
DEFLATE64(new byte[] { (byte)0x04, (byte)0x01, (byte)0x09 }),
/** BZIP2 */
BZIP2(new byte[] { (byte)0x04, (byte)0x02, (byte)0x02 }),
/**
Expand Down
2 changes: 1 addition & 1 deletion src/site/xdoc/examples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ LOOP UNTIL entry.getSize() HAS BEEN READ {
of compression and encryption algorithms used for 7z archives.
For writing only uncompressed entries, LZMA, LZMA2, BZIP2 and
Deflate are supported - reading also supports
AES-256/SHA-256.</p>
AES-256/SHA-256 and DEFLATE64.</p>

<p>Multipart archives are not supported at all.</p>

Expand Down
2 changes: 1 addition & 1 deletion src/site/xdoc/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<li>Support for Zstandard compression.</li>
<li>Read-only support for DEFLATE64 compression as
stand-alone CompressorInputStream and as method used in
ZIP archives.</li>
ZIP and 7z archives.</li>
</ul>
</subsection>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public void test7zDeflateUnarchive() throws Exception {
test7zUnarchive(getFile("bla.deflate.7z"), SevenZMethod.DEFLATE);
}

@Test
public void test7zDeflate64Unarchive() throws Exception {
test7zUnarchive(getFile("bla.deflate64.7z"), SevenZMethod.DEFLATE64);
}

@Test
public void test7zDecryptUnarchive() throws Exception {
if (isStrongCryptoAvailable()) {
Expand Down
Binary file added src/test/resources/bla.deflate64.7z
Binary file not shown.

0 comments on commit 738c708

Please sign in to comment.