-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathProjectResourceContent.cs
More file actions
56 lines (47 loc) · 1.16 KB
/
Copy pathProjectResourceContent.cs
File metadata and controls
56 lines (47 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using RPGCore.FileTree;
using RPGCore.Packages;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
namespace RPGCore.Projects;
[DebuggerDisplay("{ToString(),nq}")]
public sealed class ProjectResourceContent : IResourceContent
{
public long UncompressedSize { get; }
public IArchiveFile ArchiveEntry { get; }
internal ProjectResourceContent(IArchiveFile archiveEntry)
{
ArchiveEntry = archiveEntry;
UncompressedSize = ArchiveEntry.UncompressedSize;
}
public byte[] LoadData()
{
using var stream = ArchiveEntry.OpenRead();
byte[] buffer = new byte[ArchiveEntry.UncompressedSize];
stream.Read(buffer, 0, buffer.Length);
return buffer;
}
public async Task<byte[]> LoadDataAsync()
{
byte[] result;
using (var stream = File.Open(ArchiveEntry.FullName, FileMode.Open))
{
result = new byte[stream.Length];
await stream.ReadAsync(result, 0, (int)stream.Length);
}
return result;
}
public Stream OpenRead()
{
return ArchiveEntry.OpenRead();
}
public Stream OpenWrite()
{
return ArchiveEntry.OpenWrite();
}
/// <inheritdoc/>
public override string ToString()
{
return new MemorySize(UncompressedSize).ToString();
}
}