mirror of
https://github.com/kwsch/pkNX.git
synced 2026-08-26 20:34:07 -05:00
Add VFS
This commit is contained in:
44
pkNX.Containers/VFS/FileSystems/IFileSystem.cs
Normal file
44
pkNX.Containers/VFS/FileSystems/IFileSystem.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace pkNX.Containers.VFS;
|
||||
|
||||
public interface IFileSystem : IDisposable
|
||||
{
|
||||
IEnumerable<FileSystemPath> GetEntities(FileSystemPath path);
|
||||
bool Exists(FileSystemPath path);
|
||||
Stream CreateFile(FileSystemPath path);
|
||||
Stream OpenFile(FileSystemPath path, FileAccess access);
|
||||
void CreateDirectory(FileSystemPath path);
|
||||
void Delete(FileSystemPath path);
|
||||
|
||||
bool IsReadOnly => false;
|
||||
|
||||
public string ReadAllText(FileSystemPath path)
|
||||
{
|
||||
if (!Exists(path))
|
||||
return string.Empty;
|
||||
|
||||
using var stream = OpenFile(path, FileAccess.Read);
|
||||
using var reader = new StreamReader(stream);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
||||
public void WriteAllText(FileSystemPath path, string content)
|
||||
{
|
||||
if (!Exists(path))
|
||||
{
|
||||
CreateFile(path);
|
||||
}
|
||||
|
||||
using var stream = OpenFile(path, FileAccess.Write);
|
||||
using var writer = new StreamWriter(stream);
|
||||
writer.Write(content);
|
||||
}
|
||||
}
|
||||
|
||||
public static class IFileSystemExtensions
|
||||
{
|
||||
public static ReadOnlyFileSystem AsReadOnlyFileSystem(this IFileSystem self) => new(self);
|
||||
}
|
||||
Reference in New Issue
Block a user