deflateInit() public method

Initializes the internal stream state for compression.
public deflateInit ( int level ) : int
level int An integer value from 0 to 9 indicating the desired compression level.
return int
Beispiel #1
0
            private static zlib.ZStream CreateDeflateStream(int level, int windowBits, int memLevel, int strategy)
            {
                var stream = new zlib.ZStream();
                int result = stream.deflateInit(level, windowBits, memLevel, (zlib.CompressionStrategy)strategy);

                if (result != Z_OK)
                {
                    throw MakeError(result, null);
                }

                return(stream);
            }
Beispiel #2
0
        internal Compress(int level, int method, int wbits, int memlevel, int strategy)
        {
            zst = new ZStream();
            int err = zst.deflateInit(level, wbits);
            switch(err)
            {
                case ZlibModule.Z_OK:
                    break;

                case ZlibModule.Z_STREAM_ERROR:
                    throw PythonOps.ValueError("Invalid initialization option");

                default:
                    throw ZlibModule.zlib_error(this.zst, err, "while creating compression object");
            }
        }
Beispiel #3
0
        public static string compress([BytesConversion]IList<byte> data,
            [DefaultParameterValue(Z_DEFAULT_COMPRESSION)]int level)
        {
            byte[] input = data.ToArray();
            byte[] output = new byte[input.Length + input.Length / 1000 + 12 + 1];

            ZStream zst = new ZStream();
            zst.next_in = input;
            zst.avail_in = input.Length;
            zst.next_out = output;
            zst.avail_out = output.Length;

            int err = zst.deflateInit(level);
            switch(err)
            {
                case (Z_OK):
                    break;
                
                case (Z_STREAM_ERROR):
                    throw PythonOps.CreateThrowable(error,
                                    "Bad compression level");
                
                default:
                    zst.deflateEnd();
                    zlib_error(zst, err, "while compressing data");
                    return null;
            }

            err = zst.deflate(FlushStrategy.Z_FINISH);

            if(err != Z_STREAM_END)
            {
                zst.deflateEnd();
                throw zlib_error(zst, err, "while compressing data");
            }

            err = zst.deflateEnd();

            if(err == Z_OK)
                return PythonAsciiEncoding.Instance.GetString(output, 0, (int)zst.total_out);
            else
                throw zlib_error(zst, err, "while finishing compression");
        }
Beispiel #4
0
 /// <summary>
 /// Constructor which takes two parameters: the <paramref name="stream"/> to store compressed data in and the desired compression level.
 /// </summary>
 /// <param name="stream">A stream to be used to store compressed data.</param>
 /// <param name="level">An integer value indicating the desired compression level. The compression level can take values from 0 to 9. The maximum value indicates that the maximum compression should be achieved (but this method will be the slowest one). 0 means that no compression should be used at all. If you want to use the default compression level you can pass -1. Also you can use the constants from the <see cref="ZLibCompressionLevel" /> class.</param>
 public ZOutputStream(System.IO.Stream stream, int level)
 {
     InitBlock();
     this._stream = stream;
     z.deflateInit(level);
 }
Beispiel #5
0
            private static zlib.ZStream CreateDeflateStream(int level, int windowBits, int memLevel, int strategy) {
                var stream = new zlib.ZStream();
                int result = stream.deflateInit(level, windowBits, memLevel, (zlib.CompressionStrategy)strategy);
                if (result != Z_OK) {
                    throw MakeError(result, null);
                }

                return stream;
            }