BadScript 2
Loading...
Searching...
No Matches
BadVirtualFile.cs
Go to the documentation of this file.
2
4
9{
13 private byte[] m_Data;
14
20 internal BadVirtualFile(string name, BadVirtualDirectory? parent) : base(name, parent)
21 {
22 m_Data = Array.Empty<byte>();
23 }
24
28 public string AbsolutePath => Parent?.AbsolutePath + Name;
29
30 public override bool HasChildren => false;
31
32 public override IEnumerable<BadVirtualNode> Children => Enumerable.Empty<BadVirtualNode>();
33
38 public Stream OpenRead()
39 {
40 BadLogger.Log($"Opening File(READ) {AbsolutePath}", "BFS");
41
42 return new MemoryStream(m_Data, false);
43 }
44
50 public Stream OpenWrite(BadWriteMode mode)
51 {
52 BadLogger.Log($"Opening File(WRITE: {mode}) {AbsolutePath}", "BFS");
54
55 if (mode == BadWriteMode.CreateNew)
56 {
57 m_Data = Array.Empty<byte>();
58 }
59
60 s.Write(m_Data, 0, m_Data.Length);
61
62 s.OnDispose += () => m_Data = s.ToArray();
63
64 return s;
65 }
66}
Public facing interface for a logger.
Definition BadLogger.cs:7
static void Log(string message)
Writes a Log to the Message Handler.
Definition BadLogger.cs:26
Represents a Virtual File System Directory Entry.
string AbsolutePath
The Absolute Path of this Directory.
Implements a Virtual File System File.
override IEnumerable< BadVirtualNode > Children
Stream OpenWrite(BadWriteMode mode)
Returns a writable stream for the file.
BadVirtualFile(string name, BadVirtualDirectory? parent)
Creates a new Virtual File.
string AbsolutePath
The Absolute Path of the File.
Stream OpenRead()
Returns a readable stream for the file.
Implements a special memory stream that can be used to read and write to a virtual file.
Base class for all Virtual Filesystem Nodes.
BadVirtualDirectory? Parent
Parent Directory.
Contains Logging system for the BadScript Runtime.
Definition BadLog.cs:6
Contains the Implementation of the BadScript Virtual File System.
BadWriteMode
The Write Modes of the File System Abstraction.