NdsForge.NET 1.0.1
Read, validate, edit, compare, and build Nintendo DS and DSi images from .NET
Loading...
Searching...
No Matches
NdsFile.cs
1namespace NdsForge;
2
4public sealed class NdsFile
5{
7 private readonly IImageDataSource _source;
8
16 internal NdsFile(
17 IImageDataSource source,
18 int id,
19 string name,
20 string fullPath,
21 NdsRegion data,
22 NdsDirectory parent)
23 {
24 _source = source;
25 Id = id;
26 Name = name;
27 FullPath = fullPath;
28 Data = data;
29 Parent = parent;
30 }
31
33 public int Id { get; }
34
39 public string Name { get; }
40
42 public string FullPath { get; }
43
45 public NdsRegion Data { get; }
46
48 public NdsDirectory Parent { get; }
49
52 public Stream OpenRead() => new ImageSliceStream(_source, Data);
53
58 public async ValueTask CopyToAsync(Stream destination, CancellationToken cancellationToken = default)
59 {
60 ArgumentNullException.ThrowIfNull(destination);
61 if (!destination.CanWrite)
62 {
63 throw new ArgumentException("The NitroFS file destination must be writable.", nameof(destination));
64 }
65
66 using Stream source = OpenRead();
67 await source.CopyToAsync(destination, cancellationToken).ConfigureAwait(false);
68 }
69
73 public async ValueTask<byte[]> ReadAllBytesAsync(CancellationToken cancellationToken = default)
74 {
75 if (Data.Length > Array.MaxLength)
76 {
77 throw new IOException($"NitroFS file {FullPath} is too large to materialize as a byte array.");
78 }
79
80 byte[] data = new byte[Data.Length];
81 await _source.ReadExactlyAsync(Data.Offset, data, cancellationToken).ConfigureAwait(false);
82 return data;
83 }
84}
Materializes one FNT directory record as a navigable node while preserving its encoded child order.
string FullPath
Identifies the entry with ordinal, slash-delimited semantics such as /data/maps/map....
Definition NdsFile.cs:42
NdsRegion Data
Locates the uncompressed payload through the FAT's half-open start/end offsets.
Definition NdsFile.cs:45
async ValueTask CopyToAsync(Stream destination, CancellationToken cancellationToken=default)
Streams this allocation into a caller-owned destination without buffering the complete file in memory...
Definition NdsFile.cs:58
int Id
Indexes the FAT allocation and is also the identifier referenced by overlay table entries.
Definition NdsFile.cs:33
Stream OpenRead()
Opens a bounded, seekable stream over the file contents.
Definition NdsFile.cs:52
async ValueTask< byte[]> ReadAllBytesAsync(CancellationToken cancellationToken=default)
Reads all file contents into memory.
Definition NdsFile.cs:73
NdsDirectory Parent
Links back to the directory that assigned this file's name and starting file ID.
Definition NdsFile.cs:48
string Name
Projects each case-sensitive FNT name byte directly to the same-valued Unicode code point....
Definition NdsFile.cs:39
Identifies a bounded range of bytes in an image.
Definition NdsRegion.cs:11