Ejemplo n.º 1
0
        private async Task <MemoryStream> DeflateAsync(byte[] data, int level, bool zlib)
        {
            var memoryStream = new MemoryStream();

            var deflater = new Deflater(level, !zlib);

            using (DeflaterOutputStream outStream = new DeflaterOutputStream(memoryStream, deflater))
            {
                outStream.IsStreamOwner = false;
                await outStream.WriteAsync(data, 0, data.Length);

                await outStream.FlushAsync();

                await outStream.FinishAsync(CancellationToken.None);
            }
            return(memoryStream);
        }