ItemWithStream.cs 949 B

1234567891011121314151617181920212223242526272829303132
  1. using System.IO;
  2. namespace TriLibCore.SFB
  3. {
  4. /// <summary>Represents a platform-specific file with a Stream.</summary>
  5. public class ItemWithStream
  6. {
  7. /// <summary>Gets/Sets the item filename.</summary>
  8. public string Name { get; set; }
  9. /// <summary>Sets the item file Stream.</summary>
  10. public Stream Stream { private get; set; }
  11. /// <summary>
  12. /// Indicates if this item has valid data.
  13. /// </summary>
  14. public bool HasData => !string.IsNullOrWhiteSpace(Name) || Stream != null;
  15. /// <summary>
  16. /// Opens the Stream to read data from this item.
  17. /// </summary>
  18. /// <returns>The opened Stream.</returns>
  19. public Stream OpenStream()
  20. {
  21. if (Stream == null && Name != null)
  22. {
  23. return File.OpenRead(Name);
  24. }
  25. return Stream;
  26. }
  27. }
  28. }