Пример #1
0
        private unsafe CompressionStatus ReadDeflateOutput(byte[] outputBuffer, StreamFlag flushCode, out int bytesRead)
        {
            if (outputBuffer?.Length < 0)
            {
                throw new ArgumentException("outputbuffer length must be bigger than 0");
            }
            lock (SyncLock)
            {
                fixed(byte *bufPtr = &outputBuffer[0])
                {
                    _compression_struct.Destination     = (IntPtr)bufPtr;
                    _compression_struct.DestinationSize = outputBuffer.Length;

                    var readStatus = CompressionStreamStruct.compression_stream_process(ref _compression_struct, flushCode);

                    switch (readStatus)
                    {
                    case CompressionStatus.Ok:
                    case CompressionStatus.End:
                        bytesRead = outputBuffer.Length - (int)_compression_struct.DestinationSize;
                        break;

                    default:
                        bytesRead = 0;
                        break;
                    }
                    _finished = readStatus == CompressionStatus.End;
                    return(readStatus);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Creates the Compression stream that will handle inflation.
        /// </summary>
        private void InflateInit(CompressionAlgorithm algorithm)
        {
            _compression_struct = new CompressionStreamStruct();

            var status = CompressionStreamStruct.compression_stream_init(ref _compression_struct, StreamOperation.Decode, algorithm);

            if (status != CompressionStatus.Ok)
                throw new InvalidOperationException(status.ToString()); }
Пример #3
0
 private void Dispose(bool disposing)
 {
     if (!_isDisposed)
     {
         CompressionStreamStruct.compression_stream_destroy(ref _compression_struct);
         DeallocateInputBufferHandle();
         _isDisposed = true;
     }
 }
 public static extern CompressionStatus compression_stream_destroy(ref CompressionStreamStruct stream);
 public static extern CompressionStatus compression_stream_process(ref CompressionStreamStruct stream, StreamFlag flags);
 public static extern CompressionStatus compression_stream_init(ref CompressionStreamStruct stream, StreamOperation operation, CompressionAlgorithm algorithm);