WebDavRamfsStoreDocument.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.IO;
  3. using RamDavisk.Ramfs.Inters;
  4. using WebDAVSharp.Server.Stores;
  5. namespace RamDavisk.Ramfs
  6. {
  7. internal class WebDavRamfsStoreDocument : WebDavRamfsStoreItem, IWebDavStoreDocument
  8. {
  9. private readonly MemoryStream _buf;
  10. public WebDavRamfsStoreDocument()
  11. {
  12. _buf = new MemoryStream();
  13. }
  14. public Stream OpenReadStream() => new StreamWrap(_buf);
  15. public Stream OpenWriteStream(bool append)
  16. {
  17. try
  18. {
  19. var s = new StreamWrap(_buf);
  20. if (append) s.Position = _buf.Position;
  21. return s;
  22. }
  23. finally
  24. {
  25. ModificationDate = DateTime.Now;
  26. }
  27. }
  28. public override long Size => _buf.Length;
  29. public override string Etag => ModificationDate.GetHashCode().ToString();
  30. public override bool IsCollection => false;
  31. public override void Dispose()
  32. {
  33. _buf.Dispose();
  34. GC.Collect();
  35. }
  36. }
  37. }