GZipWritableArchiveEntry.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using SharpCompress.Common;
  5. using SharpCompress.IO;
  6. namespace SharpCompress.Archives.GZip
  7. {
  8. internal class GZipWritableArchiveEntry : GZipArchiveEntry, IWritableArchiveEntry
  9. {
  10. private readonly bool closeStream;
  11. private readonly Stream stream;
  12. internal GZipWritableArchiveEntry(GZipArchive archive, Stream stream,
  13. string path, long size, DateTime? lastModified, bool closeStream)
  14. : base(archive, null)
  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. }