public async Task <byte[]> ReadFile(FileRecord record) { var isCompressed = (Header.ArchiveFlags & BSA105ArchiveFlags.CompressedArchive) == BSA105ArchiveFlags.CompressedArchive; if ((isCompressed && !record.CompressionBit) || (!isCompressed && record.CompressionBit)) { return(await ReadCompressedFile(record)); } ArchiveStream.Seek(record.DataOffset, SeekOrigin.Begin); var fileBytes = new byte[record.Size]; await ArchiveStream.ReadAsync(fileBytes, 0, fileBytes.Length); return(fileBytes); }
public async Task <byte[]> ReadCompressedFile(FileRecord record) { ArchiveStream.Seek(record.DataOffset, SeekOrigin.Begin); var reader = new BinaryReader(ArchiveStream); var realSize = reader.ReadUInt32(); var source = new byte[record.Size - 4]; await ArchiveStream.ReadAsync(source, 0, source.Length); using (var memory = new MemoryStream(source)) { var output = LZ4Stream.Decode(memory); var targetBytes = new byte[realSize]; await output.ReadAsync(targetBytes, 0, targetBytes.Length); return(targetBytes); } }