public async Task <byte[]> DecompressAsync(byte[] data, ZlibCompressionOptions options)
        {
            var _options = GetOptions(options);
            var inStream = new MemoryStream();
            var bytes    = data;

            await inStream.WriteAsync(bytes, 0, bytes.Length);

            inStream.Position = 0;

            var outStream  = new MemoryStream();
            var outZStream = new zlib.ZOutputStream(outStream);

            try
            {
                await copyStreamAsync(inStream, outZStream, _options.DecompressBufferSize);
            }
            finally
            {
                outZStream.Close();
                outStream.Close();
                inStream.Close();
            }

            return(outStream.ToArray());
        }
        public byte[] Compress(byte[] data, ZlibCompressionOptions options)
        {
            var _options  = GetOptions(options);
            var bytes     = data;
            var outStream = new MemoryStream();
            var inStream  = new MemoryStream();

            inStream.Write(bytes, 0, bytes.Length);
            inStream.Position = 0;

            var outZStream = new zlib.ZOutputStream(outStream, zlib.zlibConst.Z_DEFAULT_COMPRESSION);

            try
            {
                copyStream(inStream, outZStream, _options.CompressBufferSize);
            }
            finally
            {
                outZStream.Close();
                outStream.Close();
                inStream.Close();
            }

            return(outStream.ToArray());
        }
        private ZlibCompressionOptions GetOptions(ZlibCompressionOptions options)
        {
            var result = (options == null) ? new ZlibCompressionOptions(): options;

            if (result.CompressBufferSize <= 0)
            {
                result.CompressBufferSize = 10420;
            }

            if (result.DecompressBufferSize <= 0)
            {
                result.DecompressBufferSize = 10420;
            }

            return(result);
        }
        public async Task <Stream> DecompressAsync(Stream data, ZlibCompressionOptions options)
        {
            var _options   = GetOptions(options);
            var inStream   = data;
            var outStream  = new MemoryStream();
            var outZStream = new zlib.ZOutputStream(outStream);

            try
            {
                await copyStreamAsync(inStream, outZStream, _options.DecompressBufferSize);
            }
            finally
            {
                outZStream.Close();
                outStream.Close();
                inStream.Close();
            }

            return(outStream);
        }
        public Stream Compress(Stream data, ZlibCompressionOptions options)
        {
            var _options  = GetOptions(options);
            var outStream = new MemoryStream();
            var inStream  = data;

            var outZStream = new zlib.ZOutputStream(outStream, zlib.zlibConst.Z_DEFAULT_COMPRESSION);

            try
            {
                copyStream(inStream, outZStream, _options.CompressBufferSize);
            }
            finally
            {
                outZStream.Close();
                outStream.Close();
                inStream.Close();
            }

            return(outStream);
        }