示例#1
0
 /// <summary>
 /// Release inflater instance
 /// </summary>
 public static void ReleaseInflater()
 {
     if (_inflater != null)
     {
         _inflater.DataAvailable -= ZLibWrapper.WriteInOutputBuffer;
         _inflater.Dispose();
         _inflater = null;
     }
 }
            public async Task Execute(IReadableChannel input, IWritableChannel output)
            {
                while (true)
                {
                    var inputBuffer = await input.ReadAsync();

                    if (inputBuffer.IsEmpty && input.Completion.IsCompleted)
                    {
                        break;
                    }

                    var writerBuffer = output.Alloc(2048);
                    var span         = inputBuffer.FirstSpan;
                    if (span.Length > 0)
                    {
                        unsafe
                        {
                            _inflater.SetInput((IntPtr)span.UnsafePointer, span.Length);

                            int written = _inflater.Inflate((IntPtr)writerBuffer.Memory.UnsafePointer, writerBuffer.Memory.Length);

                            writerBuffer.CommitBytes(written);

                            var consumed = span.Length - _inflater.AvailableInput;

                            inputBuffer = inputBuffer.Slice(0, consumed);
                        }
                    }

                    inputBuffer.Consumed();

                    await writerBuffer.FlushAsync();
                }

                input.CompleteReading();

                output.CompleteWriting();

                _inflater.Dispose();
            }
示例#3
0
            public async Task Execute(IReadableChannel input, IWritableChannel output)
            {
                while (true)
                {
                    var inputBuffer = await input.ReadAsync();

                    if (inputBuffer.IsEmpty && input.Reading.IsCompleted)
                    {
                        break;
                    }

                    var writerBuffer = output.Alloc(2048);
                    var memory       = inputBuffer.First;
                    if (memory.Length > 0)
                    {
                        unsafe
                        {
                            _inflater.SetInput((IntPtr)memory.UnsafePointer, memory.Length);

                            int written = _inflater.Inflate((IntPtr)memory.UnsafePointer, memory.Length);

                            writerBuffer.Advance(written);

                            var consumed = memory.Length - _inflater.AvailableInput;

                            inputBuffer = inputBuffer.Slice(0, consumed);
                        }
                    }

                    input.Advance(inputBuffer.End);

                    await writerBuffer.FlushAsync();
                }

                input.Complete();

                output.Complete();

                _inflater.Dispose();
            }
示例#4
0
            public async Task Execute(IReadableChannel input, IWritableChannel output)
            {
                while (true)
                {
                    await input;

                    var inputBuffer = input.BeginRead();

                    if (inputBuffer.IsEmpty && input.Completion.IsCompleted)
                    {
                        break;
                    }

                    var writerBuffer = output.Alloc(2048);
                    var span         = inputBuffer.FirstSpan;
                    if (span.Length > 0)
                    {
                        _inflater.SetInput(span.BufferPtr, span.Length);

                        int written = _inflater.Inflate(writerBuffer.Memory.BufferPtr, writerBuffer.Memory.Length);

                        writerBuffer.UpdateWritten(written);

                        var consumed = span.Length - _inflater.AvailableInput;

                        inputBuffer = inputBuffer.Slice(0, consumed);
                    }

                    input.EndRead(inputBuffer);

                    await output.WriteAsync(writerBuffer);
                }

                input.CompleteReading();

                output.CompleteWriting();

                _inflater.Dispose();
            }