FileInfoRarArchiveVolume.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 
  2. #if !NO_FILE
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using SharpCompress.Common.Rar;
  6. using SharpCompress.Common.Rar.Headers;
  7. using SharpCompress.IO;
  8. using SharpCompress.Readers;
  9. namespace SharpCompress.Archives.Rar
  10. {
  11. /// <summary>
  12. /// A rar part based on a FileInfo object
  13. /// </summary>
  14. internal class FileInfoRarArchiveVolume : RarVolume
  15. {
  16. internal FileInfoRarArchiveVolume(FileInfo fileInfo, ReaderOptions options)
  17. : base(StreamingMode.Seekable, fileInfo.OpenRead(), FixOptions(options))
  18. {
  19. FileInfo = fileInfo;
  20. FileParts = GetVolumeFileParts().ToReadOnly();
  21. }
  22. private static ReaderOptions FixOptions(ReaderOptions options)
  23. {
  24. //make sure we're closing streams with fileinfo
  25. options.LeaveStreamOpen = false;
  26. return options;
  27. }
  28. internal ReadOnlyCollection<RarFilePart> FileParts { get; }
  29. internal FileInfo FileInfo { get; }
  30. internal override RarFilePart CreateFilePart(MarkHeader markHeader, FileHeader fileHeader)
  31. {
  32. return new FileInfoRarFilePart(this, ReaderOptions.Password, markHeader, fileHeader, FileInfo);
  33. }
  34. internal override IEnumerable<RarFilePart> ReadFileParts()
  35. {
  36. return FileParts;
  37. }
  38. }
  39. }
  40. #endif