TarWritableArchiveEntry.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using SharpCompress.Common;
  5. using SharpCompress.IO;
  6. namespace SharpCompress.Archives.Tar
  7. {
  8. internal class TarWritableArchiveEntry : TarArchiveEntry, IWritableArchiveEntry
  9. {
  10. private readonly bool closeStream;
  11. private readonly Stream stream;
  12. internal TarWritableArchiveEntry(TarArchive archive, Stream stream, CompressionType compressionType,
  13. string path, long size, DateTime? lastModified, bool closeStream)
  14. : base(archive, null, compressionType)
  15. {
  16. this.stream = stream;
  17. Key = path;
  18. Size = size;
  19. LastModifiedTime = lastModified;
  20. this.closeStream = closeStream;
  21. }
  22. public override long Crc => 0;
  23. public override string Key { get; }
  24. public override long CompressedSize => 0;
  25. public override long Size { get; }
  26. public override DateTime? LastModifiedTime { get; }
  27. public override DateTime? CreatedTime => null;
  28. public override DateTime? LastAccessedTime => null;
  29. public override DateTime? ArchivedTime => null;
  30. public override bool IsEncrypted => false;
  31. public override bool IsDirectory => false;
  32. public override bool IsSplitAfter => false;
  33. internal override IEnumerable<FilePart> Parts => throw new NotImplementedException();
  34. Stream IWritableArchiveEntry.Stream => stream;
  35. public override Stream OpenEntryStream()
  36. {
  37. //ensure new stream is at the start, this could be reset
  38. stream.Seek(0, SeekOrigin.Begin);
  39. return new NonDisposingStream(stream);
  40. }
  41. internal override void Close()
  42. {
  43. if (closeStream)
  44. {
  45. stream.Dispose();
  46. }
  47. }
  48. }
  49. }