public static async Task <byte[]> DecompressAsync(byte[] byteIn, int size) { using var stream = new ZlibStream(new MemoryStream(byteIn, false), CompressionMode.Decompress, CompressionLevel.BestSpeed); var data = new byte[size]; await stream.ReadAsync(byteIn, 0, size); return(data); }
public async Task <byte[]> Decompress(byte[] compressedArray, int bufferSize) { var memoryStream = new MemoryStream(compressedArray); using (var decompressor = new ZlibStream(memoryStream, CompressionMode.Decompress)) { var buffer = new byte[bufferSize]; using (var output = new MemoryStream()) { int read; while ((read = await decompressor.ReadAsync(buffer, 0, buffer.Length)) > 0) { await output.WriteAsync(buffer, 0, read); } return(output.ToArray()); } } }
public async Task <byte[]> Decompress(byte[] compressedArray) { var memoryStream = new MemoryStream(compressedArray); using (var decompressor = new ZlibStream(memoryStream, CompressionMode.Decompress)) { var buffer = new byte[Constants.BUFFER_SIZE]; using (var output = new MemoryStream()) { int read; while ((read = await decompressor.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0) { await output.WriteAsync(buffer, 0, read).ConfigureAwait(false); } return(output.ToArray()); } } }
private static async Task <MemoryStream> InternalGetDecryptionStreamAsync(Stream input, IMS2SizeHeader size, IBufferedCipher cipher, bool zlibCompressed) { using var cs = new CipherStream(input, cipher, null); byte[] bytes = new byte[size.Size]; int readBytes; if (zlibCompressed) { using var z = new ZlibStream(cs, CompressionMode.Decompress, true); readBytes = await z.ReadAsync(bytes, 0, bytes.Length).ConfigureAwait(false); } else { readBytes = await cs.ReadAsync(bytes, 0, bytes.Length).ConfigureAwait(false); } if (readBytes != size.Size) { throw new ArgumentException("Size bytes from input do not match with header size.", nameof(input)); } return(new MemoryStream(bytes)); }