Skip to content

Commit

Permalink
Zip64 introduced seekable behavior into ZipWriter. The position may … (
Browse files Browse the repository at this point in the history
…#252)

* Zip64 introduced seekable behavior into ZipWriter.  The position may not be zero.

* Remove some dead code

* Update formats for zip64

* Make version created by and version needed to extract the same

* Running tests is faster than skipping
  • Loading branch information
adamhathcock authored May 31, 2017
1 parent b45bc85 commit 3d3ca25
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
2 changes: 1 addition & 1 deletion FORMATS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
| LZip (single file) (5) | LZip (LZMA) | Both | LZipArchive | LZipReader | LZipWriter |

1. SOLID Rars are only supported in the RarReader API.
2. Zip format supports pkware and WinzipAES encryption. However, encrypted LZMA is not supported. Zip64 reading is supported.
2. Zip format supports pkware and WinzipAES encryption. However, encrypted LZMA is not supported. Zip64 reading/writing is supported but only with seekable streams as the Zip spec doesn't support Zip64 data in post data descriptors.
3. The Tar format requires a file size in the header. If no size is specified to the TarWriter and the stream is not seekable, then an exception will be thrown.
4. The 7Zip format doesn't allow for reading as a forward-only stream so 7Zip is only supported through the Archive API
5. LZip has no support for extra data like the file name or timestamp. There is a default filename used when looking at the entry Key on the archive.
Expand Down
4 changes: 2 additions & 2 deletions src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ internal uint Write(Stream outputStream)
}
}

//constant sig, then version made by, compabitility, then version to extract
outputStream.Write(new byte[] { 80, 75, 1, 2, 0x14, 0, version, 0 }, 0, 8);
//constant sig, then version made by, then version to extract
outputStream.Write(new byte[] { 80, 75, 1, 2, version, 0, version, 0 }, 0, 8);

outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)flags), 0, 2);
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)compression), 0, 2); // zipping method
Expand Down
12 changes: 4 additions & 8 deletions src/SharpCompress/Writers/Zip/ZipWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public ZipWriter(Stream destination, ZipWriterOptions zipWriterOptions)
{
zipComment = zipWriterOptions.ArchiveComment ?? string.Empty;
isZip64 = zipWriterOptions.UseZip64;
if (destination.CanSeek)
{
streamPosition = destination.Position;
}

compressionType = zipWriterOptions.CompressionType;
compressionLevel = zipWriterOptions.DeflateCompressionLevel;
Expand Down Expand Up @@ -207,14 +211,6 @@ private void WriteFooter(uint crc, uint compressed, uint uncompressed)
OutputStream.Write(DataConverter.LittleEndian.GetBytes(uncompressed), 0, 4);
}

private void WritePostdataDescriptor(uint crc, ulong compressed, ulong uncompressed)
{
OutputStream.Write(DataConverter.LittleEndian.GetBytes(ZipHeaderFactory.POST_DATA_DESCRIPTOR), 0, 4);
OutputStream.Write(DataConverter.LittleEndian.GetBytes(crc), 0, 4);
OutputStream.Write(DataConverter.LittleEndian.GetBytes((uint)compressed), 0, 4);
OutputStream.Write(DataConverter.LittleEndian.GetBytes((uint)uncompressed), 0, 4);
}

private void WriteEndRecord(ulong size)
{
byte[] encodedComment = ArchiveEncoding.Default.GetBytes(zipComment);
Expand Down
8 changes: 0 additions & 8 deletions tests/SharpCompress.Test/Zip/Zip64Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,41 @@ public Zip64Tests()
// 4GiB + 1
const long FOUR_GB_LIMIT = ((long)uint.MaxValue) + 1;

[Fact(Skip = "Takes too long")]
[Trait("format", "zip64")]
public void Zip64_Single_Large_File()
{
// One single file, requires zip64
RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: true, forward_only: false);
}

[Fact(Skip = "Takes too long")]
[Trait("format", "zip64")]
public void Zip64_Two_Large_Files()
{
// One single file, requires zip64
RunSingleTest(2, FOUR_GB_LIMIT, set_zip64: true, forward_only: false);
}

[Fact(Skip = "Takes too long")]
[Trait("format", "zip64")]
public void Zip64_Two_Small_files()
{
// Multiple files, does not require zip64
RunSingleTest(2, FOUR_GB_LIMIT / 2, set_zip64: false, forward_only: false);
}

[Fact(Skip = "Takes too long")]
[Trait("format", "zip64")]
public void Zip64_Two_Small_files_stream()
{
// Multiple files, does not require zip64, and works with streams
RunSingleTest(2, FOUR_GB_LIMIT / 2, set_zip64: false, forward_only: true);
}

[Fact(Skip = "Takes too long")]
[Trait("format", "zip64")]
public void Zip64_Two_Small_Files_Zip64()
{
// Multiple files, use zip64 even though it is not required
RunSingleTest(2, FOUR_GB_LIMIT / 2, set_zip64: true, forward_only: false);
}

[Fact(Skip = "Takes too long")]
[Trait("format", "zip64")]
public void Zip64_Single_Large_File_Fail()
{
Expand All @@ -76,7 +70,6 @@ public void Zip64_Single_Large_File_Fail()
}
}

[Fact(Skip = "Takes too long")]
[Trait("zip64", "true")]
public void Zip64_Single_Large_File_Zip64_Streaming_Fail()
{
Expand All @@ -91,7 +84,6 @@ public void Zip64_Single_Large_File_Zip64_Streaming_Fail()
}
}

[Fact(Skip = "Takes too long")]
[Trait("zip64", "true")]
public void Zip64_Single_Large_File_Streaming_Fail()
{
Expand Down

0 comments on commit 3d3ca25

Please sign in to comment.