SeekableZipFilePart.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.IO;
  2. using SharpCompress.Common.Zip.Headers;
  3. namespace SharpCompress.Common.Zip
  4. {
  5. internal class SeekableZipFilePart : ZipFilePart
  6. {
  7. private bool _isLocalHeaderLoaded;
  8. private readonly SeekableZipHeaderFactory _headerFactory;
  9. internal SeekableZipFilePart(SeekableZipHeaderFactory headerFactory, DirectoryEntryHeader header, Stream stream)
  10. : base(header, stream)
  11. {
  12. _headerFactory = headerFactory;
  13. }
  14. internal override Stream GetCompressedStream()
  15. {
  16. if (!_isLocalHeaderLoaded)
  17. {
  18. LoadLocalHeader();
  19. _isLocalHeaderLoaded = true;
  20. }
  21. return base.GetCompressedStream();
  22. }
  23. internal string Comment => (Header as DirectoryEntryHeader).Comment;
  24. private void LoadLocalHeader()
  25. {
  26. bool hasData = Header.HasData;
  27. Header = _headerFactory.GetLocalHeader(BaseStream, Header as DirectoryEntryHeader);
  28. Header.HasData = hasData;
  29. }
  30. protected override Stream CreateBaseStream()
  31. {
  32. BaseStream.Position = Header.DataStartPosition.Value;
  33. return BaseStream;
  34. }
  35. }
  36. }