1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System.IO;
- using SharpCompress.Common.Zip.Headers;
- using SharpCompress.Compressors.Deflate;
- using SharpCompress.IO;
- namespace SharpCompress.Common.Zip
- {
- internal class StreamingZipFilePart : ZipFilePart
- {
- private Stream _decompressionStream;
- internal StreamingZipFilePart(ZipFileEntry header, Stream stream)
- : base(header, stream)
- {
- }
- protected override Stream CreateBaseStream()
- {
- return Header.PackedStream;
- }
- internal override Stream GetCompressedStream()
- {
- if (!Header.HasData)
- {
- return Stream.Null;
- }
- _decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()), Header.CompressionMethod);
- if (LeaveStreamOpen)
- {
- return new NonDisposingStream(_decompressionStream);
- }
- return _decompressionStream;
- }
- internal BinaryReader FixStreamedFileLocation(ref RewindableStream rewindableStream)
- {
- if (Header.IsDirectory)
- {
- return new BinaryReader(rewindableStream);
- }
- if (Header.HasData && !Skipped)
- {
- if (_decompressionStream == null)
- {
- _decompressionStream = GetCompressedStream();
- }
- _decompressionStream.Skip();
- DeflateStream deflateStream = _decompressionStream as DeflateStream;
- if (deflateStream != null)
- {
- rewindableStream.Rewind(deflateStream.InputBuffer);
- }
- Skipped = true;
- }
- var reader = new BinaryReader(rewindableStream);
- _decompressionStream = null;
- return reader;
- }
- }
- }
|