Exemple #1
0
        int IDeflater.GetDeflateOutput(byte[] outputBuffer)
        {
            Debug.Assert(outputBuffer != null, "Can't pass in a null output buffer!");
            Debug.Assert(!this.NeedsInput(), "GetDeflateOutput should only be called after providing input");
            this.output.UpdateBuffer(outputBuffer);
            switch (this.processingState)
            {
            case DeflaterManaged.DeflaterState.NotStarted:
                Debug.Assert(this.deflateEncoder.BytesInHistory == 0, "have leftover bytes in window");
                DeflateInput.InputState  state1 = this.input.DumpState();
                OutputBuffer.BufferState state2 = this.output.DumpState();
                this.deflateEncoder.GetBlockHeader(this.output);
                this.deflateEncoder.GetCompressedData(this.input, this.output);
                if (!this.UseCompressed(this.deflateEncoder.LastCompressionRatio))
                {
                    this.input.RestoreState(state1);
                    this.output.RestoreState(state2);
                    this.copyEncoder.GetBlock(this.input, this.output, false);
                    this.FlushInputWindows();
                    this.processingState = DeflaterManaged.DeflaterState.CheckingForIncompressible;
                    break;
                }
                this.processingState = DeflaterManaged.DeflaterState.CompressThenCheck;
                break;

            case DeflaterManaged.DeflaterState.SlowDownForIncompressible1:
                this.deflateEncoder.GetBlockFooter(this.output);
                this.processingState = DeflaterManaged.DeflaterState.SlowDownForIncompressible2;
                goto case DeflaterManaged.DeflaterState.SlowDownForIncompressible2;

            case DeflaterManaged.DeflaterState.SlowDownForIncompressible2:
                if (this.inputFromHistory.Count > 0)
                {
                    this.copyEncoder.GetBlock(this.inputFromHistory, this.output, false);
                }
                if (this.inputFromHistory.Count == 0)
                {
                    this.deflateEncoder.FlushInput();
                    this.processingState = DeflaterManaged.DeflaterState.CheckingForIncompressible;
                    break;
                }
                break;

            case DeflaterManaged.DeflaterState.StartingSmallData:
                this.deflateEncoder.GetBlockHeader(this.output);
                this.processingState = DeflaterManaged.DeflaterState.HandlingSmallData;
                goto case DeflaterManaged.DeflaterState.HandlingSmallData;

            case DeflaterManaged.DeflaterState.CompressThenCheck:
                this.deflateEncoder.GetCompressedData(this.input, this.output);
                if (!this.UseCompressed(this.deflateEncoder.LastCompressionRatio))
                {
                    this.processingState  = DeflaterManaged.DeflaterState.SlowDownForIncompressible1;
                    this.inputFromHistory = this.deflateEncoder.UnprocessedInput;
                    break;
                }
                break;

            case DeflaterManaged.DeflaterState.CheckingForIncompressible:
                Debug.Assert(this.deflateEncoder.BytesInHistory == 0, "have leftover bytes in window");
                DeflateInput.InputState  state3 = this.input.DumpState();
                OutputBuffer.BufferState state4 = this.output.DumpState();
                this.deflateEncoder.GetBlock(this.input, this.output, 8072);
                if (!this.UseCompressed(this.deflateEncoder.LastCompressionRatio))
                {
                    this.input.RestoreState(state3);
                    this.output.RestoreState(state4);
                    this.copyEncoder.GetBlock(this.input, this.output, false);
                    this.FlushInputWindows();
                    break;
                }
                break;

            case DeflaterManaged.DeflaterState.HandlingSmallData:
                this.deflateEncoder.GetCompressedData(this.input, this.output);
                break;
            }
            return(this.output.BytesWritten);
        }
Exemple #2
0
 internal void RestoreState(DeflateInput.InputState state)
 {
     this.count      = state.count;
     this.startIndex = state.startIndex;
 }