public WorkItem(int size, CompressionLevel compressLevel, CompressionStrategy strategy) { buffer = new byte[size]; // alloc 5 bytes overhead for every block (margin of safety= 2) int n = size + ((size / 32768) + 1) * 5 * 2; compressed = new byte[n]; status = (int)Status.None; compressor = new ZlibCodec(); compressor.InitializeDeflate(compressLevel, false); compressor.OutputBuffer = compressed; compressor.InputBuffer = buffer; }
public WorkItem(int size, Ionic.Zlib.CompressionLevel compressLevel, CompressionStrategy strategy, int ix) { this.buffer= new byte[size]; // alloc 5 bytes overhead for every block (margin of safety= 2) int n = size + ((size / 32768)+1) * 5 * 2; this.compressed = new byte[n]; this.compressor = new ZlibCodec(); this.compressor.InitializeDeflate(compressLevel, false); this.compressor.OutputBuffer = this.compressed; this.compressor.InputBuffer = this.buffer; this.index = ix; }
/// <summary> /// Create a ParallelDeflateOutputStream using the specified /// CompressionLevel and CompressionStrategy, and specifying whether to /// leave the captive stream open when the ParallelDeflateOutputStream is /// closed. /// </summary> /// <remarks> /// See the <see cref="ParallelDeflateOutputStream(System.IO.Stream)"/> /// constructor for example code. /// </remarks> /// <param name="stream">The stream to which compressed data will be written.</param> /// <param name="level">A tuning knob to trade speed for effectiveness.</param> /// <param name="strategy"> /// By tweaking this parameter, you may be able to optimize the compression for /// data with particular characteristics. /// </param> /// <param name="leaveOpen"> /// true if the application would like the stream to remain open after inflation/deflation. /// </param> public ParallelGZipOutputStream(System.IO.Stream stream, CompressionLevel level, CompressionStrategy strategy, bool leaveOpen) { TraceOutput(TraceBits.Lifecycle | TraceBits.Session, "-------------------------------------------------------"); TraceOutput(TraceBits.Lifecycle | TraceBits.Session, "Create {0:X8}", this.GetHashCode()); _outStream = stream; _compressLevel= level; Strategy = strategy; _leaveOpen = leaveOpen; _nBuckets = 4; // default _bufferSize = IO_BUFFER_SIZE_DEFAULT; }
internal int Initialize(ZlibCodec stream, CompressionLevel level, int method, int windowBits, int memLevel, CompressionStrategy strategy) { stream.Message = null; // validation if (windowBits < 9 || windowBits > 15) throw new ZlibException ("windowBits must be in the range 9..15."); if (memLevel < 1 || memLevel > MEM_LEVEL_MAX) throw new ZlibException (String.Format ("memLevel must be in the range 1.. {0}", MEM_LEVEL_MAX)); if (method != Z_DEFLATED) throw new ZlibException ("Unexpected value for method: it must be Z_DEFLATED."); stream.dstate = this; w_bits = windowBits; w_size = 1 << w_bits; w_mask = w_size - 1; hash_bits = memLevel + 7; hash_size = 1 << hash_bits; hash_mask = hash_size - 1; hash_shift = ((hash_bits + MIN_MATCH - 1) / MIN_MATCH); window = new byte[w_size * 2]; prev = new short[w_size]; head = new short[hash_size]; lit_bufsize = 1 << (memLevel + 6); // 16K elements by default // We overlay pending_buf and d_buf+l_buf. This works since the average // output size for (length,distance) codes is <= 24 bits. pending = new byte[lit_bufsize * 4]; d_buf = lit_bufsize / 2; l_buf = (1 + 2) * lit_bufsize; this.compressionLevel = level; this.compressionStrategy = strategy; this.method = (sbyte)method; return Reset (stream); }
public OrcCompressedBuffer(int compressionBlockSize, Protocol.CompressionKind compressionKind, CompressionStrategy compressionStrategy, Protocol.StreamKind streamKind) : this(compressionBlockSize, compressionKind, compressionStrategy) { StreamKind = streamKind; }
/// <summary> /// 设置解压参数。 /// </summary> /// <param name="level">压缩等级。</param> /// <param name="strategy">压缩策略。</param> /// <returns>如果正常返回 ZlibState.Success 。</returns> public ZlibState SetDeflateParams(CompressionLevel level, CompressionStrategy strategy) { Thrower.ThrowZlibExceptionIf(DState == null, "没有初始化 Deflate 状态。"); return(DState.SetParams(level, strategy)); }
internal int Initialize(ZlibCodec codec, CompressionLevel level, int bits, CompressionStrategy compressionStrategy) { return Initialize(codec, level, bits, MEM_LEVEL_DEFAULT, compressionStrategy); }
public ErrorCode DeflateInit2_(CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy) { EnsureNotDisposed(); EnsureState(State.NotInitialized); ErrorCode errC = Interop.zlib.DeflateInit2_(ref _zStream, level, CompressionMethod.Deflated, windowBits, memLevel, strategy); _initializationState = State.InitializedForDeflate; return errC; }
internal int SetParams( CompressionLevel level, CompressionStrategy strategy ) { int result = ZlibConstants.Z_OK; if ( compressionLevel != level ) { Config newConfig = Config.Lookup ( level ); if ( newConfig.Flavor != config.Flavor && _codec.TotalBytesIn != 0 ) { result = _codec.Deflate ( FlushType.Partial ); } compressionLevel = level; config = newConfig; SetDeflater (); } compressionStrategy = strategy; return result; }
public int SetDeflateParams(CompressionLevel level, CompressionStrategy strategy) => this.dstate?.SetParams(level, strategy);
public CompressionState DeflateInit2( ZStream strm, CompressionLevel level, int method, int windowBits, int memLevel, CompressionStrategy strategy) { int noheader = 0; strm.Msg = null; if (level == CompressionLevel.DefaultCompression) { level = CompressionLevel.Level6; } if (level == CompressionLevel.NoCompression) { memLevel = DEFNOCOMPRESSIONMEMLEVEL; } if (windowBits < 0) { // undocumented feature: suppress zlib header noheader = 1; windowBits = -windowBits; } if (memLevel < 1 || memLevel > MAXMEMLEVEL || method != ZDEFLATED || windowBits < 9 || windowBits > 15 || level < CompressionLevel.NoCompression || level > CompressionLevel.BestCompression || strategy < CompressionStrategy.DefaultStrategy || strategy > CompressionStrategy.Rle) { return(CompressionState.ZSTREAMERROR); } #if USE_QUICK if (level == ZlibCompressionLevel.ZBESTSPEED) { windowBits = 13; } #endif strm.Dstate = this; this.Noheader = noheader; this.wBits = windowBits; this.wSize = 1 << this.wBits; this.wMask = this.wSize - 1; this.hashBits = memLevel + 7; this.hashSize = 1 << this.hashBits; this.hashMask = (uint)this.hashSize - 1; this.litBufsize = 1 << (memLevel + 6); // 16K elements by default this.dBuf = this.litBufsize; this.lBuf = (1 + 2) * this.litBufsize; this.level = level; this.strategy = strategy; this.method = (byte)method; this.DynBuffers = new DynamicBuffers(this.wSize, this.hashSize, this.litBufsize * 4); return(this.DeflateReset(strm)); }
public WriterOptions(Properties tableProperties, Configuration conf) { configuration = conf; memoryManagerValue = getMemoryManager(conf); stripeSizeValue = OrcConf.STRIPE_SIZE.getLong(tableProperties, conf); blockSizeValue = OrcConf.BLOCK_SIZE.getLong(tableProperties, conf); rowIndexStrideValue = (int)OrcConf.ROW_INDEX_STRIDE.getLong(tableProperties, conf); bufferSizeValue = (int)OrcConf.BUFFER_SIZE.getLong(tableProperties, conf); blockPaddingValue = OrcConf.BLOCK_PADDING.getBoolean(tableProperties, conf); compressValue = (CompressionKind)Enum.Parse( typeof(CompressionKind), OrcConf.COMPRESS.getString(tableProperties, conf), true); string versionName = OrcConf.WRITE_FORMAT.getString(tableProperties, conf); versionValue = VersionHelper.byName(versionName); string enString = OrcConf.ENCODING_STRATEGY.getString(tableProperties, conf); _encodingStrategy = (EncodingStrategy)Enum.Parse(typeof(EncodingStrategy), enString, true); string compString = OrcConf.COMPRESSION_STRATEGY.getString(tableProperties, conf); compressionStrategy = (CompressionStrategy)Enum.Parse(typeof(CompressionStrategy), compString, true); _paddingTolerance = OrcConf.BLOCK_PADDING_TOLERANCE.getDouble(tableProperties, conf); _bloomFilterColumns = OrcConf.BLOOM_FILTER_COLUMNS.getString(tableProperties, conf); _bloomFilterFpp = OrcConf.BLOOM_FILTER_FPP.getDouble(tableProperties, conf); timeZone = TimeZoneInfo.Local.Id; }
internal int Initialize(ZlibCodec codec, CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy) { this._codec = codec; this._codec.Message = null; if ((windowBits < 9) || (windowBits > 15)) { throw new ZlibException("windowBits must be in the range 9..15."); } if ((memLevel < 1) || (memLevel > MEM_LEVEL_MAX)) { throw new ZlibException($"memLevel must be in the range 1.. {MEM_LEVEL_MAX}"); } this._codec.dstate = this; this.w_bits = windowBits; this.w_size = ((int)1) << this.w_bits; this.w_mask = this.w_size - 1; this.hash_bits = memLevel + 7; this.hash_size = ((int)1) << this.hash_bits; this.hash_mask = this.hash_size - 1; this.hash_shift = ((this.hash_bits + MIN_MATCH) - 1) / MIN_MATCH; this.window = new byte[this.w_size * 2]; this.prev = new short[this.w_size]; this.head = new short[this.hash_size]; this.lit_bufsize = ((int)1) << (memLevel + 6); this.pending = new byte[this.lit_bufsize * 4]; this._distanceOffset = this.lit_bufsize; this._lengthOffset = 3 * this.lit_bufsize; this.compressionLevel = level; this.compressionStrategy = strategy; this.Reset(); return(0); }
public int deflateInit(int level, int windowBits, int memLevel, CompressionStrategy strategy) { _dstate = new Deflate(); return(_dstate.deflateInit2(this, level, windowBits, memLevel, strategy)); }
internal int method_33(Class1068 A_0, CompressionLevel A_1, int A_2, CompressionStrategy A_3) { return(this.method_34(A_0, A_1, A_2, 8, A_3)); }
internal int Initialize( ZlibCodec codec, CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy ) { _codec = codec; _codec.Message = null; if ( windowBits < 9 || windowBits > 15 ) throw new CompressionProcessException ( "windowBits must be in the range 9..15." ); if ( memLevel < 1 || memLevel > MEM_LEVEL_MAX ) throw new CompressionProcessException ( String.Format ( "memLevel must be in the range 1.. {0}", MEM_LEVEL_MAX ) ); _codec.dstate = this; w_bits = windowBits; w_size = 1 << w_bits; w_mask = w_size - 1; hash_bits = memLevel + 7; hash_size = 1 << hash_bits; hash_mask = hash_size - 1; hash_shift = ( ( hash_bits + MIN_MATCH - 1 ) / MIN_MATCH ); window = new byte [ w_size * 2 ]; prev = new short [ w_size ]; head = new short [ hash_size ]; lit_bufsize = 1 << ( memLevel + 6 ); pending = new byte [ lit_bufsize * 4 ]; _distanceOffset = lit_bufsize; _lengthOffset = ( 1 + 2 ) * lit_bufsize; this.compressionLevel = level; this.compressionStrategy = strategy; Reset (); return ZlibConstants.Z_OK; }
private ZLibStatus deflateInit2(CompressionLevel level, int method, int windowBits, int memLevel, CompressionStrategy strategy) { int noheader = 0; // byte[] my_version=ZLIB_VERSION; // // if (version == null || version[0] != my_version[0] // || stream_size != sizeof(z_stream)) { // return Z_VERSION_ERROR; // } base.msg = null; if (level == CompressionLevel.Z_DEFAULT_COMPRESSION) level = (CompressionLevel)6; if (windowBits < 0) { // undocumented feature: suppress zlib header noheader = 1; windowBits = -windowBits; } if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || windowBits < 9 || windowBits > 15 || level < 0 || level > (CompressionLevel)9 || strategy < 0 || strategy > CompressionStrategy.Z_HUFFMAN_ONLY) { return ZLibStatus.Z_STREAM_ERROR; } this.noheader = noheader; _windowBits = windowBits; _windowSize = 1 << _windowBits; _windowMask = _windowSize - 1; _hashBits = memLevel + 7; _hashSize = 1 << _hashBits; _hashMask = _hashSize - 1; _hashShift = ((_hashBits + MIN_MATCH - 1) / MIN_MATCH); _window = new byte[_windowSize * 2]; _previous = new short[_windowSize]; _head = new short[_hashSize]; lit_bufsize = 1 << (memLevel + 6); // 16K elements by default // We overlay pending_buf and d_buf+l_buf. This works since the average // output size for (length,distance) codes is <= 24 bits. pending_buf = new byte[lit_bufsize * 4]; _pendingBufferSize = lit_bufsize * 4; d_buf = lit_bufsize / 2; l_buf = (1 + 2) * lit_bufsize; this.level = level; //System.out.println("level="+level); this.strategy = strategy; this._method = (byte)method; return deflateReset(); }
/// <summary> /// Set the CompressionStrategy and CompressionLevel for a deflation session. /// </summary> /// <param name="level">the level of compression to use.</param> /// <param name="strategy">the strategy to use for compression.</param> /// <returns>Z_OK if all goes well.</returns> public int SetDeflateParams(CompressionLevel level, CompressionStrategy strategy) { if (dstate == null) throw new ZlibException("No Deflate State!"); return dstate.SetParams(level, strategy); }
/// <summary> /// Deflate algorithm initialization /// </summary> /// <param name="strm">ZStream object</param> /// <param name="level">Compression level</param> /// <param name="method">Compression method</param> /// <param name="windowBits">Window bits</param> /// <param name="memLevel">Memory level</param> /// <param name="strategy">Compression strategy</param> /// <returns>Operation result code</returns> internal int deflateInit2(ZStream strm, int level, int method, int windowBits, int memLevel, CompressionStrategy strategy) { int noheader = 0; strm.msg = null; if (level == Z_DEFAULT_COMPRESSION) level = 6; if (windowBits < 0) { // undocumented feature: suppress zlib header noheader = 1; windowBits = -windowBits; } if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || windowBits < 9 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > CompressionStrategy.Z_HUFFMAN_ONLY) { return (int)ZLibResultCode.Z_STREAM_ERROR; } strm.dstate = (Deflate)this; this.NoHeader = noheader; w_bits = windowBits; w_size = 1 << w_bits; w_mask = w_size - 1; hash_bits = memLevel + 7; hash_size = 1 << hash_bits; hash_mask = hash_size - 1; hash_shift = ((hash_bits + MIN_MATCH - 1) / MIN_MATCH); window = new byte[w_size * 2]; prev = new short[w_size]; head = new short[hash_size]; lit_bufsize = 1 << (memLevel + 6); // 16K elements by default // We overlay Pending_buf and d_buf+l_buf. This works since the average // output size for (length,distance) codes is <= 24 bits. Pending_buf = new byte[lit_bufsize * 4]; pending_buf_size = lit_bufsize * 4; d_buf = lit_bufsize; l_buf = (1 + 2) * lit_bufsize; this.level = level; this.strategy = strategy; this.method = (byte)method; return deflateReset(strm); }
internal int Initialize(ZlibCodec codec, CompressionLevel level, int bits, CompressionStrategy compressionStrategy) { return(Initialize(codec, level, bits, MemLevelDefault, compressionStrategy)); }
internal int SetParams(CompressionLevel level, CompressionStrategy strategy) { int result = ZlibConstants.Z_OK; if (compressionLevel != level) { Config newConfig = Config.Lookup(level); // change in the deflate flavor (Fast vs slow vs none)? if (newConfig.Flavor != config.Flavor && _codec.TotalBytesIn != 0) { // Flush the last buffer: result = _codec.Deflate(FlushType.Partial); } compressionLevel = level; config = newConfig; SetDeflater(); } // no need to flush with change in strategy? Really? compressionStrategy = strategy; return result; }
public int deflateInit(int level, int windowBits, int memLevel, CompressionStrategy strategy) { _dstate = new Deflate(); return _dstate.deflateInit2(this, level, windowBits, memLevel, strategy); }
public OrcCompressedBuffer(int compressionBlockSize, Protocol.CompressionKind compressionKind, CompressionStrategy compressionStrategy) { _compressionBlockSize = compressionBlockSize; _compressionKind = compressionKind; _compressionStrategy = compressionStrategy; }
/// <summary> /// Dynamically update the compression level and compression strategy. The interpretation of level is as in <see cref="deflateInit(int)"/>. This can be used to switch between compression and straight copy of the input data, or to switch to a different kind of input data requiring a different strategy. If the compression level is changed, the input available so far is compressed with the old level (and may be flushed); the new level will take effect only at the next call of <see cref="deflate" /> /// </summary> /// <param name="level">An integer value indicating the desired compression level.</param> /// <param name="strategy">A <see cref="FlushStrategy">flush strategy</see> to use.</param> /// <remarks> /// Before the call of <see cref="deflateParams" />, the stream state must be set as for a call of <see cref="deflate" />, since the currently available input may have to be compressed and flushed. In particular, <see cref="avail_out" /> must be non-zero. /// </remarks> /// <returns> /// deflateParams returns <see cref="ZLibResultCode.Z_OK" /> if success, <see cref="ZLibResultCode.Z_STREAM_ERROR" /> if the source stream state was inconsistent or if a parameter was invalid, <see cref="ZLibResultCode.Z_BUF_ERROR" /> if <see cref="avail_out" /> was zero. /// </returns> public int deflateParams(int level, CompressionStrategy strategy) { if (_dstate == null) return (int)ZLibResultCode.Z_STREAM_ERROR; return _dstate.deflateParams(this, level, strategy); }
internal int SetParams(ZlibCodec strm, CompressionLevel _level, CompressionStrategy _strategy) { int result = ZlibConstants.Z_OK; if (configTable [(int)compressionLevel].func != configTable [(int)_level].func && strm.TotalBytesIn != 0) { // Flush the last buffer: result = strm.Deflate (ZlibConstants.Z_PARTIAL_FLUSH); } if (compressionLevel != _level) { compressionLevel = _level; max_lazy_match = configTable [(int)compressionLevel].max_lazy; good_match = configTable [(int)compressionLevel].good_length; nice_match = configTable [(int)compressionLevel].nice_length; max_chain_length = configTable [(int)compressionLevel].max_chain; } compressionStrategy = _strategy; return result; }
public ErrorCode DeflateInit2_(CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy) { EnsureNotDisposed(); EnsureState(State.NotInitialized); ErrorCode errC = Interop.zlib.DeflateInit2_(ref _zStream, level, CompressionMethod.Deflated, windowBits, memLevel, strategy); _initializationState = State.InitializedForDeflate; return(errC); }
protected ZLibStatus deflateParams(CompressionLevel level, CompressionStrategy strategy) { if (dstate == null) return ZLibStatus.Z_STREAM_ERROR; return dstate.deflateParams(this, level, strategy); }
public static ErrorCode CreateZLibStreamForDeflate(out ZLibStreamHandle zLibStreamHandle, CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy) { zLibStreamHandle = new ZLibStreamHandle(); return(zLibStreamHandle.DeflateInit2_(level, windowBits, memLevel, strategy)); }
/// <summary> /// Create a ParallelDeflateOutputStream using the specified /// CompressionLevel and CompressionStrategy, and specifying whether to /// leave the captive stream open when the ParallelDeflateOutputStream is /// closed. /// </summary> /// <remarks> /// See the <see cref="ParallelDeflateOutputStream(System.IO.Stream)"/> /// constructor for example code. /// </remarks> /// <param name="stream">The stream to which compressed data will be written.</param> /// <param name="level">A tuning knob to trade speed for effectiveness.</param> /// <param name="strategy"> /// By tweaking this parameter, you may be able to optimize the compression for /// data with particular characteristics. /// </param> /// <param name="leaveOpen"> /// true if the application would like the stream to remain open after inflation/deflation. /// </param> public ParallelDeflateOutputStream(Stream stream, CompressionLevel level, CompressionStrategy strategy, bool leaveOpen) { TraceOutput(TraceBits.Lifecycle | TraceBits.Session, "-------------------------------------------------------"); TraceOutput(TraceBits.Lifecycle | TraceBits.Session, "Create {0:X8}", GetHashCode()); _compressLevel = level; _leaveOpen = leaveOpen; Strategy = strategy; BuffersPerCore = 4; // default _writingDone = new ManualResetEvent(false); _sessionReset = new ManualResetEvent(false); _outStream = stream; }
public WorkItem(int size, Newegg.Oversea.Silverlight.Utilities.Compression.CompressionLevel compressLevel, CompressionStrategy strategy) { buffer = new byte[size]; // alloc 5 bytes overhead for every block (margin of safety= 2) int n = size + ((size / 32768) + 1) * 5 * 2; compressed = new byte[n]; status = (int)Status.None; compressor = new ZlibCodec(); compressor.InitializeDeflate(compressLevel, false); compressor.OutputBuffer = compressed; compressor.InputBuffer = buffer; }
public ZLibStatus deflateParams(CompressionLevel level, CompressionStrategy strategy) { return this.deflateParams(this, level, strategy); }
internal int Initialize(ZlibCodec codec, CompressionLevel level, int bits, CompressionStrategy compressionStrategy) { return(Initialize(codec, level, bits, MEM_LEVEL_DEFAULT, compressionStrategy)); }
/// <summary> /// Create a ParallelDeflateOutputStream using the specified /// CompressionLevel and CompressionStrategy, and specifying whether to /// leave the captive stream open when the ParallelDeflateOutputStream is /// closed. /// </summary> /// <remarks> /// See the <see cref="ParallelDeflateOutputStream(System.IO.Stream)"/> /// constructor for example code. /// </remarks> /// <param name="stream">The stream to which compressed data will be written.</param> /// <param name="level">A tuning knob to trade speed for effectiveness.</param> /// <param name="strategy"> /// By tweaking this parameter, you may be able to optimize the compression for /// data with particular characteristics. /// </param> /// <param name="leaveOpen"> /// true if the application would like the stream to remain open after inflation/deflation. /// </param> public ParallelDeflateOutputStream(System.IO.Stream stream, CompressionLevel level, CompressionStrategy strategy, bool leaveOpen) { TraceOutput(TraceBits.Lifecycle | TraceBits.Session, "-------------------------------------------------------"); TraceOutput(TraceBits.Lifecycle | TraceBits.Session, "Create {0:X8}", this.GetHashCode()); _outStream = stream; _compressLevel= level; Strategy = strategy; _leaveOpen = leaveOpen; this.MaxBufferPairs = 16; // default }
internal int Initialize(ZlibCodec codec, CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy) { _codec = codec; _codec.Message = null; if (windowBits < 9 || windowBits > 15) { throw new ZlibException("windowBits must be in the range 9..15."); } if (memLevel < 1 || memLevel > MEM_LEVEL_MAX) { throw new ZlibException($"memLevel must be in the range 1.. {MEM_LEVEL_MAX}"); } _codec.dstate = this; w_bits = windowBits; w_size = 1 << w_bits; w_mask = w_size - 1; hash_bits = memLevel + 7; hash_size = 1 << hash_bits; hash_mask = hash_size - 1; hash_shift = (hash_bits + MIN_MATCH - 1) / MIN_MATCH; window = new byte[w_size * 2]; prev = new short[w_size]; head = new short[hash_size]; lit_bufsize = 1 << memLevel + 6; pending = new byte[lit_bufsize * 4]; _distanceOffset = lit_bufsize; _lengthOffset = 3 * lit_bufsize; compressionLevel = level; compressionStrategy = strategy; Reset(); return(0); }
public ZLibStatus deflateParams(CompressionLevel _level, CompressionStrategy _strategy) { ZLibStatus err = ZLibStatus.Z_OK; if (_level == CompressionLevel.Z_DEFAULT_COMPRESSION) { _level = (CompressionLevel)6; } if (_level < 0 || _level > (CompressionLevel)9 || _strategy < 0 || _strategy > CompressionStrategy.Z_HUFFMAN_ONLY) { return ZLibStatus.Z_STREAM_ERROR; } if (config_table[level].Function != config_table[_level].Function && base.total_in != 0) { // Flush the last buffer: err = this.deflate(FlushType.Z_PARTIAL_FLUSH); } if (level != _level) { level = _level; _maxLazyMatch = config_table[level].MaxLazy; good_match = config_table[level].GoodLength; nice_match = config_table[level].NiceLength; _maxChainLength = config_table[level].MaxChain; } strategy = _strategy; return err; }
void SerializeIntoBuffer(object metadata, IReadOnlyList <object> events, out int startOffset, out IDescriptorSerializerContext serializerContext, out BlockType blockType, out int lenWithoutEndPadding, out ByteBuffer block) { startOffset = (int)EndBufferLen + HeaderSize; var writer = new ByteBufferWriter(); writer.WriteBlock(_zeroes.AsSpan(0, startOffset)); serializerContext = Mapping; if (metadata != null) { serializerContext = serializerContext.StoreNewDescriptors(writer, metadata); } if (events != null) { foreach (var o in events) { serializerContext = serializerContext.StoreNewDescriptors(writer, o); } if (events.Count == 0) { events = null; } } serializerContext.FinishNewDescriptors(writer); blockType = BlockType.FirstBlock; if (serializerContext.SomeTypeStored) { blockType |= BlockType.HasTypeDeclaration; } if (metadata != null) { serializerContext.StoreObject(writer, metadata); blockType |= BlockType.HasMetadata; } if (events != null) { if (events.Count == 1) { serializerContext.StoreObject(writer, events[0]); blockType |= BlockType.HasOneEvent; } else { writer.WriteVUInt32((uint)events.Count); foreach (var o in events) { serializerContext.StoreObject(writer, o); } blockType |= BlockType.HasMoreEvents; } } lenWithoutEndPadding = (int)writer.GetCurrentPosition(); writer.WriteBlock(_zeroes.AsSpan(0, (int)(SectorSize - 1))); block = writer.Data; if (CompressionStrategy.ShouldTryToCompress(lenWithoutEndPadding - startOffset)) { var compressedBlock = ByteBuffer.NewSync(block.Buffer, startOffset, lenWithoutEndPadding - startOffset); if (CompressionStrategy.Compress(ref compressedBlock)) { blockType |= BlockType.Compressed; Array.Copy(compressedBlock.Buffer, compressedBlock.Offset, block.Buffer, startOffset, compressedBlock.Length); lenWithoutEndPadding = startOffset + compressedBlock.Length; Array.Copy(_zeroes, 0, block.Buffer, lenWithoutEndPadding, (int)SectorSize - 1); } } }
public static ErrorCode CreateZLibStreamForDeflate(out ZLibStreamHandle zLibStreamHandle, CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy) { zLibStreamHandle = new ZLibStreamHandle(); return zLibStreamHandle.DeflateInit2_(level, windowBits, memLevel, strategy); }
internal int Initialize(ZlibCodec codec, CompressionLevel level, int bits, CompressionStrategy compressionStrategy) { return(this.Initialize(codec, level, bits, DeflateManager.MEM_LEVEL_DEFAULT, compressionStrategy)); }
/// <summary> /// Sets deflate algorithm parameters /// </summary> internal int deflateParams(ZStream strm, int level, CompressionStrategy strategy) { int err = (int)ZLibResultCode.Z_OK; if (level == Z_DEFAULT_COMPRESSION) { level = 6; } if (level < 0 || level > 9 || strategy < 0 || strategy > CompressionStrategy.Z_HUFFMAN_ONLY) { return (int)ZLibResultCode.Z_STREAM_ERROR; } if (config_table[this._level].func != config_table[level].func && strm.total_in != 0) { // Flush the last buffer: err = strm.deflate(FlushStrategy.Z_PARTIAL_FLUSH); } if (this._level != level) { this._level = level; max_lazy_match = config_table[this._level].max_lazy; good_match = config_table[this._level].good_length; nice_match = config_table[this._level].nice_length; max_chain_length = config_table[this._level].max_chain; } this.strategy = strategy; return err; }
internal int Initialize(ZlibCodec codec, CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy) { this._codec = codec; this._codec.Message = null; if (windowBits < 9 || windowBits > 15) { throw new ZlibException("windowBits must be in the range 9..15."); } if (memLevel < 1 || memLevel > DeflateManager.MEM_LEVEL_MAX) { throw new ZlibException(string.Format("memLevel must be in the range 1.. {0}", DeflateManager.MEM_LEVEL_MAX)); } this._codec.dstate = this; this.w_bits = windowBits; this.w_size = 1 << this.w_bits; this.w_mask = this.w_size - 1; this.hash_bits = memLevel + 7; this.hash_size = 1 << this.hash_bits; this.hash_mask = this.hash_size - 1; this.hash_shift = (this.hash_bits + DeflateManager.MIN_MATCH - 1) / DeflateManager.MIN_MATCH; this.window = new byte[this.w_size * 2]; this.prev = new short[this.w_size]; this.head = new short[this.hash_size]; this.lit_bufsize = 1 << memLevel + 6; this.pending = new byte[this.lit_bufsize * 4]; this._distanceOffset = this.lit_bufsize; this._lengthOffset = 3 * this.lit_bufsize; this.compressionLevel = level; this.compressionStrategy = strategy; this.Reset(); return(0); }
internal int Initialize(ZlibCodec codec, CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy) { _codec = codec; _codec.Message = null; // validation if (windowBits < 9 || windowBits > 15) throw new ZlibException("windowBits must be in the range 9..15."); if (memLevel < 1 || memLevel > MEM_LEVEL_MAX) throw new ZlibException(String.Format("memLevel must be in the range 1.. {0}", MEM_LEVEL_MAX)); _codec.dstate = this; w_bits = windowBits; w_size = 1 << w_bits; w_mask = w_size - 1; hash_bits = memLevel + 7; hash_size = 1 << hash_bits; hash_mask = hash_size - 1; hash_shift = ((hash_bits + MIN_MATCH - 1) / MIN_MATCH); window = new byte[w_size * 2]; prev = new short[w_size]; head = new short[hash_size]; // for memLevel==8, this will be 16384, 16k lit_bufsize = 1 << (memLevel + 6); // Use a single array as the buffer for data pending compression, // the output distance codes, and the output length codes (aka tree). // orig comment: This works just fine since the average // output size for (length,distance) codes is <= 24 bits. pending = new byte[lit_bufsize * 4]; _distanceOffset = lit_bufsize; _lengthOffset = (1 + 2) * lit_bufsize; // So, for memLevel 8, the length of the pending buffer is 65536. 64k. // The first 16k are pending bytes. // The middle slice, of 32k, is used for distance codes. // The final 16k are length codes. this.compressionLevel = level; this.compressionStrategy = strategy; Reset(); return ZlibConstants.Z_OK; }
/// <summary> /// Sets the compression strategy. By default CompressionStrategy.Default is used /// </summary> /// <param name="compressionStrategy">Compression strategy</param> /// <returns>Settings</returns> public ExcelFileGeneratorSettings SetCompressionStrategy(CompressionStrategy compressionStrategy) { _compressionStrategy = compressionStrategy; return(this); }
/// <summary> /// Sets the compression strategy. By default CompressionStrategy.Default is used /// </summary> /// <param name="compressionStrategy">Compression strategy</param> /// <returns>Settings</returns> public ExcelFileGeneratorSettings SetCompressionStrategy(CompressionStrategy compressionStrategy) { _compressionStrategy = compressionStrategy; return this; }