예제 #1
0
        public BlockCompressionBuffer(int blockSize)
        {
            // https://github.com/madler/zlib/blob/2fa463bacfff79181df1a5270fb67cc679a53e71/compress.c#L81-L86
            // compressBound(sourceLen): sourceLen + sourceLen/4096 + sourceLen/16384 + sourceLen/33554432 + 13

            Input  = new byte[blockSize];
            Output = new byte[Zlib.compressBound(blockSize)];
        }
예제 #2
0
        private static int CompressBlock(byte[] inputBlock, byte[] outputBlock, int read)
        {
            int compressedSize = outputBlock.Length;

            int result = Zlib.compress2(outputBlock, ref compressedSize, inputBlock, read, 9); // 1-9, fast to slow, -1 for default

            if (!(result == 0))
            {
                throw new ZlibException(result);
            }

            return(compressedSize);

            //var compressed = new MemoryStream(outputBlock, true);

            //var deflate = new DeflateStream(compressed, CompressionLevel.Optimal, true);
            //deflate.Write(inputBlock, 0, read);
            //deflate.Close();

            //return (int)compressed.Position;
        }