mirror of
https://github.com/kwsch/pkNX.git
synced 2026-09-10 19:45:12 -05:00
Initial Commit
This commit is contained in:
31
pkNX.Containers/SingleFileContainer.cs
Normal file
31
pkNX.Containers/SingleFileContainer.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace pkNX.Containers
|
||||
{
|
||||
public class SingleFileContainer : IFileContainer
|
||||
{
|
||||
public string FilePath { get; set; }
|
||||
public bool Modified { get; set; }
|
||||
public int Count => 1;
|
||||
|
||||
public byte[] Data;
|
||||
public SingleFileContainer(byte[] data) => Data = data;
|
||||
public SingleFileContainer(BinaryReader br) => Data = br.ReadBytes((int) br.BaseStream.Length);
|
||||
|
||||
public SingleFileContainer(string path)
|
||||
{
|
||||
FilePath = path;
|
||||
Data = File.ReadAllBytes(path);
|
||||
}
|
||||
|
||||
public byte[] this[int index] { get => Data; set => Data = value; }
|
||||
public Task<byte[][]> GetFiles() => new Task<byte[][]>(() => new[] {Data});
|
||||
public Task<byte[]> GetFile(int file, int subFile = 0) => new Task<byte[]>(() => Data);
|
||||
public Task SetFile(int file, byte[] value, int subFile = 0) => new Task(() => Data = value);
|
||||
public Task SaveAs(string path, ContainerHandler handler, CancellationToken token) => new Task(() => Dump(path, handler));
|
||||
public void Dump(string path, ContainerHandler handler) => File.WriteAllBytes(path ?? FilePath, Data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user