EditorTool3D/Assets/TriLib/TriLibStandaloneFileBrowser/StandaloneFileBrowser/ItemWithStream.cs

32 lines
918 B
C#
Raw Normal View History

2024-12-17 23:11:00 +08:00
using System.IO;
namespace TriLibCore.SFB
{
/// <summary>Represents a platform-specific file with a Stream.</summary>
public class ItemWithStream
{
/// <summary>Gets/Sets the item filename.</summary>
public string Name { get; set; }
/// <summary>Sets the item file Stream.</summary>
public Stream Stream { private get; set; }
/// <summary>
/// Indicates if this item has valid data.
/// </summary>
public bool HasData => !string.IsNullOrWhiteSpace(Name) || Stream != null;
/// <summary>
/// Opens the Stream to read data from this item.
/// </summary>
/// <returns>The opened Stream.</returns>
public Stream OpenStream()
{
if (Stream == null && Name != null)
{
return File.OpenRead(Name);
}
return Stream;
}
}
}