Пример #1
0
 internal DeflaterManaged()
 {
     this.deflateEncoder  = new FastEncoder();
     this.copyEncoder     = new CopyEncoder();
     this.input           = new DeflateInput();
     this.output          = new OutputBuffer();
     this.processingState = DeflaterManaged.DeflaterState.NotStarted;
 }
Пример #2
0
        void IDeflater.SetInput(byte[] inputBuffer, int startIndex, int count)
        {
            Debug.Assert(this.input.Count == 0, "We have something left in previous input!");
            this.input.Buffer     = inputBuffer;
            this.input.Count      = count;
            this.input.StartIndex = startIndex;
            if (count <= 0 || count >= 256)
            {
                return;
            }
            switch (this.processingState)
            {
            case DeflaterManaged.DeflaterState.NotStarted:
            case DeflaterManaged.DeflaterState.CheckingForIncompressible:
                this.processingState = DeflaterManaged.DeflaterState.StartingSmallData;
                break;

            case DeflaterManaged.DeflaterState.CompressThenCheck:
                this.processingState = DeflaterManaged.DeflaterState.HandlingSmallData;
                break;
            }
        }
Пример #3
0
 void IDeflater.SetInput(byte[] inputBuffer, int startIndex, int count)
 {
     this.input.Buffer     = inputBuffer;
     this.input.Count      = count;
     this.input.StartIndex = startIndex;
     if (count > 0 && count < 256)
     {
         DeflaterManaged.DeflaterState deflaterState = this.processingState;
         if (deflaterState != DeflaterManaged.DeflaterState.NotStarted)
         {
             if (deflaterState == DeflaterManaged.DeflaterState.CompressThenCheck)
             {
                 this.processingState = DeflaterManaged.DeflaterState.HandlingSmallData;
                 return;
             }
             if (deflaterState != DeflaterManaged.DeflaterState.CheckingForIncompressible)
             {
                 return;
             }
         }
         this.processingState = DeflaterManaged.DeflaterState.StartingSmallData;
         return;
     }
 }
Пример #4
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);
        }
Пример #5
0
        int IDeflater.GetDeflateOutput(byte[] outputBuffer)
        {
            this.output.UpdateBuffer(outputBuffer);
            switch (this.processingState)
            {
            case DeflaterManaged.DeflaterState.NotStarted:
            {
                DeflateInput.InputState  state  = 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(state);
                    this.output.RestoreState(state2);
                    this.copyEncoder.GetBlock(this.input, this.output, false);
                    this.FlushInputWindows();
                    this.processingState = DeflaterManaged.DeflaterState.CheckingForIncompressible;
                    goto IL_23A;
                }
                this.processingState = DeflaterManaged.DeflaterState.CompressThenCheck;
                goto IL_23A;
            }

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

            case DeflaterManaged.DeflaterState.SlowDownForIncompressible2:
                break;

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

            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;
                    goto IL_23A;
                }
                goto IL_23A;

            case DeflaterManaged.DeflaterState.CheckingForIncompressible:
            {
                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();
                    goto IL_23A;
                }
                goto IL_23A;
            }

            case DeflaterManaged.DeflaterState.HandlingSmallData:
                goto IL_223;

            default:
                goto IL_23A;
            }
            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;
                goto IL_23A;
            }
            goto IL_23A;
IL_223:
            this.deflateEncoder.GetCompressedData(this.input, this.output);
IL_23A:
            return(this.output.BytesWritten);
        }