TarEntry.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using SharpCompress.Common.Tar.Headers;
  5. using SharpCompress.IO;
  6. using System.Text;
  7. namespace SharpCompress.Common.Tar
  8. {
  9. public class TarEntry : Entry
  10. {
  11. private readonly TarFilePart _filePart;
  12. internal TarEntry(TarFilePart filePart, CompressionType type)
  13. {
  14. this._filePart = filePart;
  15. CompressionType = type;
  16. }
  17. public override CompressionType CompressionType { get; }
  18. public override long Crc => 0;
  19. public override string Key => _filePart.Header.Name;
  20. public override long CompressedSize => _filePart.Header.Size;
  21. public override long Size => _filePart.Header.Size;
  22. public override DateTime? LastModifiedTime => _filePart.Header.LastModifiedTime;
  23. public override DateTime? CreatedTime => null;
  24. public override DateTime? LastAccessedTime => null;
  25. public override DateTime? ArchivedTime => null;
  26. public override bool IsEncrypted => false;
  27. public override bool IsDirectory => _filePart.Header.EntryType == EntryType.Directory;
  28. public override bool IsSplitAfter => false;
  29. internal override IEnumerable<FilePart> Parts => _filePart.AsEnumerable<FilePart>();
  30. internal static IEnumerable<TarEntry> GetEntries(StreamingMode mode, Stream stream,
  31. CompressionType compressionType, ArchiveEncoding archiveEncoding)
  32. {
  33. foreach (TarHeader h in TarHeaderFactory.ReadHeader(mode, stream, archiveEncoding))
  34. {
  35. if (h != null)
  36. {
  37. if (mode == StreamingMode.Seekable)
  38. {
  39. yield return new TarEntry(new TarFilePart(h, stream), compressionType);
  40. }
  41. else
  42. {
  43. yield return new TarEntry(new TarFilePart(h, null), compressionType);
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }