public async ValueTask <IMemoryOwner <byte> > ReadEntryAsync(PakEntry entry, CancellationToken cancellationToken = default) { var taskData = entry.ReadAsync(SourceStream, cancellationToken); var buf = taskData.IsCompletedSuccessfully ? taskData.Result : await taskData.ConfigureAwait(false); if (entry.IsEncrypted) { if (_aesProvider is null) { throw new PakEncryptedException("Pak file contains encrypted entries. AES encryption key is necessary for reading this asset."); } _aesProvider.Decrypt(buf.Memory); } if (entry.IsCompressed) { var decompressTask = UnrealCompression.DecompressAsync(buf.Memory, entry, cancellationToken); var result = decompressTask.IsCompletedSuccessfully ? decompressTask.Result : await decompressTask.ConfigureAwait(false); buf.Dispose(); return(result); } else { return(buf); } }
public IMemoryOwner <byte> ReadEntry(PakEntry entry) { var buf = entry.Read(SourceStream); if (entry.IsEncrypted) { if (_aesProvider is null) { throw new PakEncryptedException("Pak file contains encrypted entries. AES encryption key is necessary for reading this asset."); } _aesProvider.Decrypt(buf.Memory); } if (entry.IsCompressed) { var decompressed = UnrealCompression.Decompress(buf.Memory, entry); buf.Dispose(); return(decompressed); } else { return(buf); } }