90 lines
1.9 KiB
C#
90 lines
1.9 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BITKit.IO
|
|
{
|
|
public class FileProvider : IStorageFile
|
|
{
|
|
readonly FileInfo fileInfo;
|
|
public FileProvider(FileInfo fileInfo)
|
|
{
|
|
this.fileInfo = fileInfo;
|
|
}
|
|
public FileProvider(string path)
|
|
{
|
|
this.fileInfo = new FileInfo(path);
|
|
}
|
|
public Stream CreateFile()
|
|
{
|
|
return File.Create(fileInfo.FullName);
|
|
}
|
|
|
|
public Task<Stream> CreateFileAsync()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public string GetFileType()
|
|
{
|
|
return fileInfo.Extension;
|
|
}
|
|
|
|
public DateTime GetLastUpdated()
|
|
{
|
|
return fileInfo.LastWriteTime;
|
|
}
|
|
|
|
public string GetName()
|
|
{
|
|
return fileInfo.Name;
|
|
}
|
|
|
|
public string GetPath()
|
|
{
|
|
return fileInfo.FullName;
|
|
}
|
|
|
|
public long GetSize()
|
|
{
|
|
return fileInfo.Length;
|
|
}
|
|
|
|
public string GetText()
|
|
{
|
|
return File.ReadAllText(fileInfo.FullName);
|
|
}
|
|
|
|
public async Task<string> GetTextAsync()
|
|
{
|
|
return await File.ReadAllTextAsync(fileInfo.FullName);
|
|
}
|
|
|
|
public Stream OpenRead()
|
|
{
|
|
return File.OpenRead(fileInfo.FullName);
|
|
}
|
|
|
|
public async Task<Stream> OpenReadAsync()
|
|
{
|
|
await UniTask.Yield();
|
|
return OpenRead();
|
|
}
|
|
|
|
public Stream OpenWrite()
|
|
{
|
|
return File.OpenWrite(fileInfo.FullName);
|
|
}
|
|
|
|
public async Task<Stream> OpenWriteAsync()
|
|
{
|
|
await UniTask.Yield();
|
|
return OpenWrite();
|
|
}
|
|
}
|
|
}
|