public ZDeflateStream(Stream compressed, Constants.Level level = Constants.Level.BestCompression, Constants.Strategy strategy = Constants.Strategy.DefaultStrategy, int memLevel = 9, bool useZlibFormat = false, int windowBits = Constants.MaxBufferSize) { Constants.RetCode ret; _compressed = compressed; _buffer = new byte[1 << 15]; unsafe { fixed(ZStream *pZstream = &_zstrm) { ret = Zlib.DeflateInit2(pZstream, (int)level, 8, useZlibFormat ? windowBits : -windowBits, memLevel, strategy); } } if (ret != Constants.RetCode.OK) { throw Contracts.Except("Could not initialize zstream. Error code: {0}", ret); } _zstrm.AvailOut = (uint)_buffer.Length; }
private ZlibImpl(ArgumentsBase args, bool isDeflate) { Contracts.CheckUserArg(args.CompressionLevel == null || (0 <= args.CompressionLevel && args.CompressionLevel <= 9), nameof(args.CompressionLevel), "Must be in range 0 to 9 or null"); Contracts.CheckUserArg(8 <= args.WindowBits && args.WindowBits <= 15, nameof(args.WindowBits), "Must be in range 8 to 15"); Contracts.CheckUserArg(1 <= args.MemoryLevel && args.MemoryLevel <= 9, nameof(args.MemoryLevel), "Must be in range 1 to 9"); Contracts.CheckUserArg(Enum.IsDefined(typeof(Constants.Strategy), args.Strategy), nameof(args.Strategy), "Value was not defined"); if (args.CompressionLevel == null) { _level = Constants.Level.DefaultCompression; } else { _level = (Constants.Level)args.CompressionLevel; } Contracts.Assert(Enum.IsDefined(typeof(Constants.Level), _level)); _windowBits = args.WindowBits; _isDeflate = isDeflate; _memoryLevel = args.MemoryLevel; _strategy = args.Strategy; }
public static unsafe Constants.RetCode DeflateInit2(ZStream *strm, int level, int method, int windowBits, int memLevel, Constants.Strategy strategy) { return(deflateInit2_(strm, level, method, windowBits, memLevel, strategy, zlibVersion(), sizeof(ZStream))); }
private static unsafe extern Constants.RetCode deflateInit2_(ZStream *strm, int level, int method, int windowBits, int memLevel, Constants.Strategy strategy, byte *version, int streamSize);