ZipWritableArchiveEntry.cs 1.9 KB

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