TarFilePart.cs 972 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.IO;
  2. using SharpCompress.Common.Tar.Headers;
  3. using SharpCompress.IO;
  4. namespace SharpCompress.Common.Tar
  5. {
  6. internal class TarFilePart : FilePart
  7. {
  8. private readonly Stream _seekableStream;
  9. internal TarFilePart(TarHeader header, Stream seekableStream)
  10. : base(header.ArchiveEncoding)
  11. {
  12. _seekableStream = seekableStream;
  13. Header = header;
  14. }
  15. internal TarHeader Header { get; }
  16. internal override string FilePartName => Header.Name;
  17. internal override Stream GetCompressedStream()
  18. {
  19. if (_seekableStream != null)
  20. {
  21. _seekableStream.Position = Header.DataStartPosition.Value;
  22. return new ReadOnlySubStream(_seekableStream, Header.Size);
  23. }
  24. return Header.PackedStream;
  25. }
  26. internal override Stream GetRawStream()
  27. {
  28. return null;
  29. }
  30. }
  31. }