public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext) { var fileStream = await fileSystem.OpenFileAsync(filePath); // Decompress, if necessary using var br = new BinaryReaderX(fileStream, true); fileStream.Position = 9; if (br.ReadString(4) == "nns_") { _wasCompressed = true; fileStream.Position = 0; var decompressedStream = new MemoryStream(); NintendoCompressor.Decompress(fileStream, decompressedStream); fileStream.Close(); fileStream = decompressedStream; } fileStream.Position = 0; Images = new List <IKanvasImage> { new KanvasImage(EncodingDefinition, _img.Load(fileStream)) }; }
private IList <ChnkSection> ReadSections(BinaryReaderX br) { // Read raw chunks var chunks = new List <ChnkSection>(); while (br.BaseStream.Position < br.BaseStream.Length) { chunks.Add(br.ReadType <ChnkSection>()); } // Decompress chunk data foreach (var chunk in chunks) { if (chunk.decompressedSize == 0) { continue; } var ms = new MemoryStream(); NintendoCompressor.Decompress(new MemoryStream(chunk.data), ms); ms.Position = 0; chunk.data = ms.ToArray(); } return(chunks); }
private Stream Decompress(Stream input) { using var br = new BinaryReaderX(input, true); input.Position = 5; var magic = br.ReadString(4); if (magic != "F3XT") { _wasCompressed = false; return(input); } _wasCompressed = true; var ms = new MemoryStream(); input.Position = 0; _compMethod = NintendoCompressor.PeekCompressionMethod(input); NintendoCompressor.Decompress(input, ms); ms.Position = 0; return(ms); }
private Stream Decompress(Stream input) { var output = new MemoryStream(); NintendoCompressor.Decompress(input, output); output.Position = 0; return(output); }