Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SharpCompress/Archives/Zip/ZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ bool closeStream
protected override IReader CreateReaderForSolidExtraction()
{
var stream = Volumes.Single().Stream;
stream.Position = 0;
((IStreamStack)stream).StackSeek(0);
return ZipReader.Open(stream, ReaderOptions, Entries);
}
}
1 change: 0 additions & 1 deletion src/SharpCompress/Common/Zip/StreamingZipFilePart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ internal BinaryReader FixStreamedFileLocation(ref SharpCompressStream rewindable
if (_decompressionStream is DeflateStream deflateStream)
{
((IStreamStack)rewindableStream).StackSeek(0);
//rewindableStream.Rewind(deflateStream.InputBuffer);
}

Skipped = true;
Expand Down
14 changes: 13 additions & 1 deletion src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@ internal IEnumerable<ZipHeader> ReadStreamHeader(Stream stream)
{
if (stream is not SharpCompressStream) //ensure the stream is already a SharpCompressStream. So the buffer/size will already be set
{
throw new ArgumentException("Stream must be a SharpCompressStream", nameof(stream));
//the original code wrapped this with RewindableStream. Wrap with SharpCompressStream as we can get the buffer size
if (stream is SourceStream src)
{
stream = new SharpCompressStream(
stream,
src.ReaderOptions.LeaveStreamOpen,
bufferSize: src.ReaderOptions.BufferSize
);
}
else
{
throw new ArgumentException("Stream must be a SharpCompressStream", nameof(stream));
}
}
SharpCompressStream rewindableStream = (SharpCompressStream)stream;

Expand Down
19 changes: 19 additions & 0 deletions tests/SharpCompress.Test/ArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,25 @@ IEnumerable<string> testArchives
}
}

protected void ArchiveExtractToDirectory(
string testArchive,
ReaderOptions? readerOptions = null
) => ArchiveExtractToDirectory(ArchiveFactory.AutoFactory, testArchive, readerOptions);

protected void ArchiveExtractToDirectory(
IArchiveFactory archiveFactory,
string testArchive,
ReaderOptions? readerOptions = null
)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
using (var archive = archiveFactory.Open(new FileInfo(testArchive), readerOptions))
{
archive.ExtractToDirectory(SCRATCH_FILES_PATH);
}
VerifyFiles();
}

protected void ArchiveFileRead(
IArchiveFactory archiveFactory,
string testArchive,
Expand Down
2 changes: 1 addition & 1 deletion tests/SharpCompress.Test/ReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ReaderOptions options
{
UseReader(reader, expectedCompression);
protectedStream.ThrowOnDispose = false;
Assert.False(testStream.IsDisposed, "{nameof(testStream)} prematurely closed");
Assert.False(testStream.IsDisposed, $"{nameof(testStream)} prematurely closed");
}

// Boolean XOR -- If the stream should be left open (true), then the stream should not be diposed (false)
Expand Down
4 changes: 4 additions & 0 deletions tests/SharpCompress.Test/Zip/ZipArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public void WinZip26_X_Multi_ArchiveFileRead() =>
[Fact]
public void Zip_Deflate_ArchiveFileRead() => ArchiveFileRead("Zip.deflate.zip");

[Fact]
public void Zip_Deflate_ArchiveExtractToDirectory() =>
ArchiveExtractToDirectory("Zip.deflate.zip");

//will detect and load other files
[Fact]
public void Zip_Deflate_Multi_ArchiveFirstFileRead() =>
Expand Down
Loading