aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlkaline Thunder <[email protected]>2018-12-28 01:16:53 -0500
committerAlkaline Thunder <[email protected]>2018-12-28 01:16:53 -0500
commit6995abe190fad72892fb621758914ea2e2ebe92d (patch)
tree79a7aa1299cd324f9ba5df56954e9721c02132a6
parente127819f16d7c87d12b7a76696ca4d84b2c86ddb (diff)
downloadshiftos-challenge-6995abe190fad72892fb621758914ea2e2ebe92d.tar.gz
shiftos-challenge-6995abe190fad72892fb621758914ea2e2ebe92d.tar.bz2
shiftos-challenge-6995abe190fad72892fb621758914ea2e2ebe92d.zip
Filesystem can now read and write files.
-rw-r--r--ShiftOS/ShiftOS/FilesystemContext.cs64
1 files changed, 64 insertions, 0 deletions
diff --git a/ShiftOS/ShiftOS/FilesystemContext.cs b/ShiftOS/ShiftOS/FilesystemContext.cs
index 2d68794..96d3832 100644
--- a/ShiftOS/ShiftOS/FilesystemContext.cs
+++ b/ShiftOS/ShiftOS/FilesystemContext.cs
@@ -62,5 +62,69 @@ namespace ShiftOS
{
return Path.Combine(_workingDirectory, ResolveToAbsolutePath(InPath).Replace("/", Path.DirectorySeparatorChar.ToString()));
}
+
+ public Stream Open(string InPath, FileMode InFileMode)
+ {
+ return File.Open(MapToEnvironmentPath(InPath), InFileMode);
+ }
+
+ public Stream OpenRead(string InPath)
+ {
+ return File.OpenRead(this.MapToEnvironmentPath(InPath));
+ }
+
+ public Stream OpenWrite(string InPath)
+ {
+ return File.OpenWrite(this.MapToEnvironmentPath(InPath));
+ }
+
+ public StreamReader OpenText(string InPath)
+ {
+ return File.OpenText(this.MapToEnvironmentPath(InPath));
+ }
+
+ public string ReadAllText(string InPath)
+ {
+ using (var sr = OpenText(InPath))
+ {
+ return sr.ReadToEnd();
+ }
+ }
+
+ public string[] ReadAllLines(string InPath)
+ {
+ return ReadAllText(InPath).Split(new[] { Environment.NewLine.ToString() }, StringSplitOptions.None);
+ }
+
+ public byte[] ReadAllBytes(string InPath)
+ {
+ using (var s = OpenRead(InPath))
+ {
+ byte[] bytes = new byte[s.Length];
+ s.Read(bytes, 0, bytes.Length);
+ return bytes;
+ }
+ }
+
+ public void WriteAllBytes(string InPath, byte[] InBytes)
+ {
+ using (var s = OpenWrite(InPath))
+ {
+ s.SetLength(InBytes.Length);
+ s.Write(InBytes, 0, InBytes.Length);
+ }
+ }
+
+ public void WriteAllText(string InPath, string InText)
+ {
+ WriteAllBytes(InPath, Encoding.UTF8.GetBytes(InText));
+ }
+
+ public void WriteAllLines(string InPath, string[] InLines)
+ {
+ WriteAllText(InPath, string.Join(Environment.NewLine, InLines));
+ }
+
+
}
}