コード例 #1
0
 public void Reset()
 {
     gzipHeaderSubstate   = GZIPHeaderState.ReadingID1;
     gzipFooterSubstate   = GZIPHeaderState.ReadingCRC;
     gzipCrc32            = 0;
     gzipOutputStreamSize = 0;
 }
コード例 #2
0
ファイル: GZipDecoder.cs プロジェクト: lovenets/hprose-dotnet
 public bool ReadGzipFooter()
 {
     this.input.SkipToByteBoundary();
     if (this.gzipFooterSubstate == GZIPHeaderState.ReadingCRC) {
         while (this.loopCounter < 4) {
             int bits = this.input.GetBits(8);
             if (bits < 0) {
                 return false;
             }
             this.gzipCrc32 |= (uint)(bits << (8 * this.loopCounter));
             this.loopCounter++;
         }
         this.gzipFooterSubstate = GZIPHeaderState.ReadingFileSize;
         this.loopCounter = 0;
     }
     if (this.gzipFooterSubstate == GZIPHeaderState.ReadingFileSize) {
         if (this.loopCounter == 0) {
             this.gzipOutputStreamSize = 0;
         }
         while (this.loopCounter < 4) {
             int num2 = this.input.GetBits(8);
             if (num2 < 0) {
                 return false;
             }
             this.gzipOutputStreamSize |= (uint)(num2 << (8 * this.loopCounter));
             this.loopCounter++;
         }
     }
     return true;
 }
コード例 #3
0
ファイル: GZipDecoder.cs プロジェクト: 284247028/MvvmCross
 public void Reset()
 {
     gzipHeaderSubstate = GZIPHeaderState.ReadingID1;
     gzipFooterSubstate = GZIPHeaderState.ReadingCRC;
     gzipCrc32 = 0;
     gzipOutputStreamSize = 0;
 }
コード例 #4
0
        public bool ReadGzipFooter()
        {
            input.SkipToByteBoundary();
            if (gzipFooterSubstate == GZIPHeaderState.ReadingCRC)
            {
                while (loopCounter < 4)
                {
                    int bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzipCrc32 |= ((uint)bits << (8 * loopCounter));
                    loopCounter++;
                }
                gzipFooterSubstate = GZIPHeaderState.ReadingFileSize;
                loopCounter        = 0;
            }

            if (gzipFooterSubstate == GZIPHeaderState.ReadingFileSize)
            {
                if (loopCounter == 0)
                {
                    gzipOutputStreamSize = 0;
                }

                while (loopCounter < 4)
                {
                    int bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzipOutputStreamSize |= ((uint)bits << (8 * loopCounter));
                    loopCounter++;
                }
            }

            return(true);
        }
コード例 #5
0
 public bool ReadGzipFooter()
 {
     this.input.SkipToByteBoundary();
     if (this.gzipFooterSubstate == GZIPHeaderState.ReadingCRC)
     {
         while (this.loopCounter < 4)
         {
             int bits = this.input.GetBits(8);
             if (bits < 0)
             {
                 return(false);
             }
             this.gzipCrc32 |= (uint)(bits << (8 * this.loopCounter));
             this.loopCounter++;
         }
         this.gzipFooterSubstate = GZIPHeaderState.ReadingFileSize;
         this.loopCounter        = 0;
     }
     if (this.gzipFooterSubstate == GZIPHeaderState.ReadingFileSize)
     {
         if (this.loopCounter == 0)
         {
             this.gzipOutputStreamSize = 0;
         }
         while (this.loopCounter < 4)
         {
             int num2 = this.input.GetBits(8);
             if (num2 < 0)
             {
                 return(false);
             }
             this.gzipOutputStreamSize |= (uint)(num2 << (8 * this.loopCounter));
             this.loopCounter++;
         }
     }
     return(true);
 }
コード例 #6
0
ファイル: GZipDecoder.cs プロジェクト: lovenets/hprose-dotnet
        public bool ReadGzipHeader()
        {
            int bits;
            switch (this.gzipHeaderSubstate) {
                case GZIPHeaderState.ReadingID1:
                    bits = this.input.GetBits(8);
                    if (bits >= 0) {
                        if (bits != 0x1f) {
                            throw new InvalidDataException("The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.");
                        }
                        this.gzipHeaderSubstate = GZIPHeaderState.ReadingID2;
                        break;
                    }
                    return false;

                case GZIPHeaderState.ReadingID2:
                    break;

                case GZIPHeaderState.ReadingCM:
                    goto Label_00AF;

                case GZIPHeaderState.ReadingFLG:
                    goto Label_00DD;

                case GZIPHeaderState.ReadingMMTime:
                    goto Label_0105;

                case GZIPHeaderState.ReadingXFL:
                    goto Label_0141;

                case GZIPHeaderState.ReadingOS:
                    goto Label_015B;

                case GZIPHeaderState.ReadingXLen1:
                    goto Label_0175;

                case GZIPHeaderState.ReadingXLen2:
                    goto Label_01A3;

                case GZIPHeaderState.ReadingXLenData:
                    goto Label_01D5;

                case GZIPHeaderState.ReadingFileName:
                    goto Label_0217;

                case GZIPHeaderState.ReadingComment:
                    goto Label_0249;

                case GZIPHeaderState.ReadingCRC16Part1:
                    goto Label_027C;

                case GZIPHeaderState.ReadingCRC16Part2:
                    goto Label_02AB;

                case GZIPHeaderState.Done:
                    goto Label_02C6;

                default:
                    throw new InvalidDataException("Decoder is in some unknown state. This might be caused by corrupted data.");
            }
            bits = this.input.GetBits(8);
            if (bits < 0) {
                return false;
            }
            if (bits != 0x8b) {
                throw new InvalidDataException("The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.");
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingCM;
            Label_00AF:
            bits = this.input.GetBits(8);
            if (bits < 0) {
                return false;
            }
            if (bits != 8) {
                throw new InvalidDataException("The compression mode specified in GZip header is unknown.");
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingFLG;
            Label_00DD:
            bits = this.input.GetBits(8);
            if (bits < 0) {
                return false;
            }
            this.gzip_header_flag = bits;
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingMMTime;
            this.loopCounter = 0;
            Label_0105:
            bits = 0;
            while (this.loopCounter < 4) {
                if (this.input.GetBits(8) < 0) {
                    return false;
                }
                this.loopCounter++;
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingXFL;
            this.loopCounter = 0;
            Label_0141:
            if (this.input.GetBits(8) < 0) {
                return false;
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingOS;
            Label_015B:
            if (this.input.GetBits(8) < 0) {
                return false;
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingXLen1;
            Label_0175:
            if ((this.gzip_header_flag & 4) == 0) {
                goto Label_0217;
            }
            bits = this.input.GetBits(8);
            if (bits < 0) {
                return false;
            }
            this.gzip_header_xlen = bits;
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingXLen2;
            Label_01A3:
            bits = this.input.GetBits(8);
            if (bits < 0) {
                return false;
            }
            this.gzip_header_xlen |= bits << 8;
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingXLenData;
            this.loopCounter = 0;
            Label_01D5:
            bits = 0;
            while (this.loopCounter < this.gzip_header_xlen) {
                if (this.input.GetBits(8) < 0) {
                    return false;
                }
                this.loopCounter++;
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingFileName;
            this.loopCounter = 0;
            Label_0217:
            if ((this.gzip_header_flag & 8) == 0) {
                this.gzipHeaderSubstate = GZIPHeaderState.ReadingComment;
            }
            else {
                do {
                    bits = this.input.GetBits(8);
                    if (bits < 0) {
                        return false;
                    }
                }
                while (bits != 0);
                this.gzipHeaderSubstate = GZIPHeaderState.ReadingComment;
            }
            Label_0249:
            if ((this.gzip_header_flag & 0x10) == 0) {
                this.gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part1;
            }
            else {
                do {
                    bits = this.input.GetBits(8);
                    if (bits < 0) {
                        return false;
                    }
                }
                while (bits != 0);
                this.gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part1;
            }
            Label_027C:
            if ((this.gzip_header_flag & 2) == 0) {
                this.gzipHeaderSubstate = GZIPHeaderState.Done;
                goto Label_02C6;
            }
            if (this.input.GetBits(8) < 0) {
                return false;
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part2;
            Label_02AB:
            if (this.input.GetBits(8) < 0) {
                return false;
            }
            this.gzipHeaderSubstate = GZIPHeaderState.Done;
            Label_02C6:
            return true;
        }
コード例 #7
0
        public bool ReadGzipHeader()
        {
            while (true)
            {
                int bits;
                switch (gzipHeaderSubstate)
                {
                case GZIPHeaderState.ReadingID1:
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    if (bits != 0x1F)
                    {
                        throw new InvalidDataException("SR.CorruptedGZipHeader");
                    }
                    gzipHeaderSubstate = GZIPHeaderState.ReadingID2;
                    goto case GZIPHeaderState.ReadingID2;

                case GZIPHeaderState.ReadingID2:
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    if (bits != 0x8b)
                    {
                        throw new InvalidDataException("SR.CorruptedGZipHeader");
                    }

                    gzipHeaderSubstate = GZIPHeaderState.ReadingCM;
                    goto case GZIPHeaderState.ReadingCM;

                case GZIPHeaderState.ReadingCM:
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    if (bits != 0x8)
                    {             // compression mode must be 8 (deflate)
                        throw new InvalidDataException("SR.UnknownCompressionMode");
                    }

                    gzipHeaderSubstate = GZIPHeaderState.ReadingFLG;;
                    goto case GZIPHeaderState.ReadingFLG;

                case GZIPHeaderState.ReadingFLG:
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzip_header_flag   = bits;
                    gzipHeaderSubstate = GZIPHeaderState.ReadingMMTime;
                    loopCounter        = 0; // 4 MMTIME bytes
                    goto case GZIPHeaderState.ReadingMMTime;

                case GZIPHeaderState.ReadingMMTime:
                    bits = 0;
                    while (loopCounter < 4)
                    {
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return(false);
                        }

                        loopCounter++;
                    }

                    gzipHeaderSubstate = GZIPHeaderState.ReadingXFL;
                    loopCounter        = 0;
                    goto case GZIPHeaderState.ReadingXFL;

                case GZIPHeaderState.ReadingXFL:          // ignore XFL
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzipHeaderSubstate = GZIPHeaderState.ReadingOS;
                    goto case GZIPHeaderState.ReadingOS;

                case GZIPHeaderState.ReadingOS:          // ignore OS
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzipHeaderSubstate = GZIPHeaderState.ReadingXLen1;
                    goto case GZIPHeaderState.ReadingXLen1;

                case GZIPHeaderState.ReadingXLen1:
                    if ((gzip_header_flag & ExtraFieldsFlag) == 0)
                    {
                        goto case GZIPHeaderState.ReadingFileName;
                    }

                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzip_header_xlen   = bits;
                    gzipHeaderSubstate = GZIPHeaderState.ReadingXLen2;
                    goto case GZIPHeaderState.ReadingXLen2;

                case GZIPHeaderState.ReadingXLen2:
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzip_header_xlen  |= (bits << 8);
                    gzipHeaderSubstate = GZIPHeaderState.ReadingXLenData;
                    loopCounter        = 0; // 0 bytes of XLEN data read so far
                    goto case GZIPHeaderState.ReadingXLenData;

                case GZIPHeaderState.ReadingXLenData:
                    bits = 0;
                    while (loopCounter < gzip_header_xlen)
                    {
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return(false);
                        }

                        loopCounter++;
                    }
                    gzipHeaderSubstate = GZIPHeaderState.ReadingFileName;
                    loopCounter        = 0;
                    goto case GZIPHeaderState.ReadingFileName;

                case GZIPHeaderState.ReadingFileName:
                    if ((gzip_header_flag & FileNameFlag) == 0)
                    {
                        gzipHeaderSubstate = GZIPHeaderState.ReadingComment;
                        goto case GZIPHeaderState.ReadingComment;
                    }

                    do
                    {
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return(false);
                        }

                        if (bits == 0)
                        {       // see '\0' in the file name string
                            break;
                        }
                    } while (true);

                    gzipHeaderSubstate = GZIPHeaderState.ReadingComment;
                    goto case GZIPHeaderState.ReadingComment;

                case GZIPHeaderState.ReadingComment:
                    if ((gzip_header_flag & CommentFlag) == 0)
                    {
                        gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part1;
                        goto case GZIPHeaderState.ReadingCRC16Part1;
                    }

                    do
                    {
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return(false);
                        }

                        if (bits == 0)
                        {       // see '\0' in the file name string
                            break;
                        }
                    } while (true);

                    gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part1;
                    goto case GZIPHeaderState.ReadingCRC16Part1;

                case GZIPHeaderState.ReadingCRC16Part1:
                    if ((gzip_header_flag & CRCFlag) == 0)
                    {
                        gzipHeaderSubstate = GZIPHeaderState.Done;
                        goto case GZIPHeaderState.Done;
                    }

                    bits = input.GetBits(8);         // ignore crc
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part2;
                    goto case GZIPHeaderState.ReadingCRC16Part2;

                case GZIPHeaderState.ReadingCRC16Part2:
                    bits = input.GetBits(8);         // ignore crc
                    if (bits < 0)
                    {
                        return(false);
                    }

                    gzipHeaderSubstate = GZIPHeaderState.Done;
                    goto case GZIPHeaderState.Done;

                case GZIPHeaderState.Done:
                    return(true);

                default:
                    Debug.Assert(false, "We should not reach unknown state!");
                    throw new InvalidDataException("SR.UnknownState");
                }
            }
        }
コード例 #8
0
        public bool ReadGzipHeader()
        {
            int bits;

            switch (this.gzipHeaderSubstate)
            {
            case GZIPHeaderState.ReadingID1:
                bits = this.input.GetBits(8);
                if (bits >= 0)
                {
                    if (bits != 0x1f)
                    {
                        throw new InvalidDataException("The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.");
                    }
                    this.gzipHeaderSubstate = GZIPHeaderState.ReadingID2;
                    break;
                }
                return(false);

            case GZIPHeaderState.ReadingID2:
                break;

            case GZIPHeaderState.ReadingCM:
                goto Label_00AF;

            case GZIPHeaderState.ReadingFLG:
                goto Label_00DD;

            case GZIPHeaderState.ReadingMMTime:
                goto Label_0105;

            case GZIPHeaderState.ReadingXFL:
                goto Label_0141;

            case GZIPHeaderState.ReadingOS:
                goto Label_015B;

            case GZIPHeaderState.ReadingXLen1:
                goto Label_0175;

            case GZIPHeaderState.ReadingXLen2:
                goto Label_01A3;

            case GZIPHeaderState.ReadingXLenData:
                goto Label_01D5;

            case GZIPHeaderState.ReadingFileName:
                goto Label_0217;

            case GZIPHeaderState.ReadingComment:
                goto Label_0249;

            case GZIPHeaderState.ReadingCRC16Part1:
                goto Label_027C;

            case GZIPHeaderState.ReadingCRC16Part2:
                goto Label_02AB;

            case GZIPHeaderState.Done:
                goto Label_02C6;

            default:
                throw new InvalidDataException("Decoder is in some unknown state. This might be caused by corrupted data.");
            }
            bits = this.input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            if (bits != 0x8b)
            {
                throw new InvalidDataException("The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.");
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingCM;
Label_00AF:
            bits = this.input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            if (bits != 8)
            {
                throw new InvalidDataException("The compression mode specified in GZip header is unknown.");
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingFLG;
Label_00DD:
            bits = this.input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzip_header_flag   = bits;
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingMMTime;
            this.loopCounter        = 0;
Label_0105:
            bits = 0;
            while (this.loopCounter < 4)
            {
                if (this.input.GetBits(8) < 0)
                {
                    return(false);
                }
                this.loopCounter++;
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingXFL;
            this.loopCounter        = 0;
Label_0141:
            if (this.input.GetBits(8) < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingOS;
Label_015B:
            if (this.input.GetBits(8) < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingXLen1;
Label_0175:
            if ((this.gzip_header_flag & 4) == 0)
            {
                goto Label_0217;
            }
            bits = this.input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzip_header_xlen   = bits;
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingXLen2;
Label_01A3:
            bits = this.input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzip_header_xlen  |= bits << 8;
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingXLenData;
            this.loopCounter        = 0;
Label_01D5:
            bits = 0;
            while (this.loopCounter < this.gzip_header_xlen)
            {
                if (this.input.GetBits(8) < 0)
                {
                    return(false);
                }
                this.loopCounter++;
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingFileName;
            this.loopCounter        = 0;
Label_0217:
            if ((this.gzip_header_flag & 8) == 0)
            {
                this.gzipHeaderSubstate = GZIPHeaderState.ReadingComment;
            }
            else
            {
                do
                {
                    bits = this.input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }
                }while (bits != 0);
                this.gzipHeaderSubstate = GZIPHeaderState.ReadingComment;
            }
Label_0249:
            if ((this.gzip_header_flag & 0x10) == 0)
            {
                this.gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part1;
            }
            else
            {
                do
                {
                    bits = this.input.GetBits(8);
                    if (bits < 0)
                    {
                        return(false);
                    }
                }while (bits != 0);
                this.gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part1;
            }
Label_027C:
            if ((this.gzip_header_flag & 2) == 0)
            {
                this.gzipHeaderSubstate = GZIPHeaderState.Done;
                goto Label_02C6;
            }
            if (this.input.GetBits(8) < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part2;
Label_02AB:
            if (this.input.GetBits(8) < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GZIPHeaderState.Done;
Label_02C6:
            return(true);
        }
コード例 #9
0
ファイル: GZipDecoder.cs プロジェクト: 284247028/MvvmCross
        public bool ReadGzipHeader()
        {

            while (true)
            {
                int bits;
                switch (gzipHeaderSubstate)
                {
                    case GZIPHeaderState.ReadingID1:
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return false;
                        }

                        if (bits != 0x1F)
                        {
                            throw new InvalidDataException("SR.CorruptedGZipHeader");
                        }
                        gzipHeaderSubstate = GZIPHeaderState.ReadingID2;
                        goto case GZIPHeaderState.ReadingID2;

                    case GZIPHeaderState.ReadingID2:
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return false;
                        }

                        if (bits != 0x8b)
                        {
                            throw new InvalidDataException("SR.CorruptedGZipHeader");
                        }

                        gzipHeaderSubstate = GZIPHeaderState.ReadingCM;
                        goto case GZIPHeaderState.ReadingCM;

                    case GZIPHeaderState.ReadingCM:
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return false;
                        }

                        if (bits != 0x8)
                        {         // compression mode must be 8 (deflate)
                            throw new InvalidDataException("SR.UnknownCompressionMode");
                        }

                        gzipHeaderSubstate = GZIPHeaderState.ReadingFLG; ;
                        goto case GZIPHeaderState.ReadingFLG;

                    case GZIPHeaderState.ReadingFLG:
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return false;
                        }

                        gzip_header_flag = bits;
                        gzipHeaderSubstate = GZIPHeaderState.ReadingMMTime;
                        loopCounter = 0; // 4 MMTIME bytes 
                        goto case GZIPHeaderState.ReadingMMTime;

                    case GZIPHeaderState.ReadingMMTime:
                        bits = 0;
                        while (loopCounter < 4)
                        {
                            bits = input.GetBits(8);
                            if (bits < 0)
                            {
                                return false;
                            }

                            loopCounter++;
                        }

                        gzipHeaderSubstate = GZIPHeaderState.ReadingXFL;
                        loopCounter = 0;
                        goto case GZIPHeaderState.ReadingXFL;

                    case GZIPHeaderState.ReadingXFL:      // ignore XFL 
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return false;
                        }

                        gzipHeaderSubstate = GZIPHeaderState.ReadingOS;
                        goto case GZIPHeaderState.ReadingOS;

                    case GZIPHeaderState.ReadingOS:      // ignore OS 
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return false;
                        }

                        gzipHeaderSubstate = GZIPHeaderState.ReadingXLen1;
                        goto case GZIPHeaderState.ReadingXLen1;

                    case GZIPHeaderState.ReadingXLen1:
                        if ((gzip_header_flag & ExtraFieldsFlag) == 0)
                        {
                            goto case GZIPHeaderState.ReadingFileName;
                        }

                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return false;
                        }

                        gzip_header_xlen = bits;
                        gzipHeaderSubstate = GZIPHeaderState.ReadingXLen2;
                        goto case GZIPHeaderState.ReadingXLen2;

                    case GZIPHeaderState.ReadingXLen2:
                        bits = input.GetBits(8);
                        if (bits < 0)
                        {
                            return false;
                        }

                        gzip_header_xlen |= (bits << 8);
                        gzipHeaderSubstate = GZIPHeaderState.ReadingXLenData;
                        loopCounter = 0; // 0 bytes of XLEN data read so far
                        goto case GZIPHeaderState.ReadingXLenData;

                    case GZIPHeaderState.ReadingXLenData:
                        bits = 0;
                        while (loopCounter < gzip_header_xlen)
                        {
                            bits = input.GetBits(8);
                            if (bits < 0)
                            {
                                return false;
                            }

                            loopCounter++;
                        }
                        gzipHeaderSubstate = GZIPHeaderState.ReadingFileName;
                        loopCounter = 0;
                        goto case GZIPHeaderState.ReadingFileName;

                    case GZIPHeaderState.ReadingFileName:
                        if ((gzip_header_flag & FileNameFlag) == 0)
                        {
                            gzipHeaderSubstate = GZIPHeaderState.ReadingComment;
                            goto case GZIPHeaderState.ReadingComment;
                        }

                        do
                        {
                            bits = input.GetBits(8);
                            if (bits < 0)
                            {
                                return false;
                            }

                            if (bits == 0)
                            {   // see '\0' in the file name string 
                                break;
                            }
                        } while (true);

                        gzipHeaderSubstate = GZIPHeaderState.ReadingComment;
                        goto case GZIPHeaderState.ReadingComment;

                    case GZIPHeaderState.ReadingComment:
                        if ((gzip_header_flag & CommentFlag) == 0)
                        {
                            gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part1;
                            goto case GZIPHeaderState.ReadingCRC16Part1;
                        }

                        do
                        {
                            bits = input.GetBits(8);
                            if (bits < 0)
                            {
                                return false;
                            }

                            if (bits == 0)
                            {   // see '\0' in the file name string 
                                break;
                            }
                        } while (true);

                        gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part1;
                        goto case GZIPHeaderState.ReadingCRC16Part1;

                    case GZIPHeaderState.ReadingCRC16Part1:
                        if ((gzip_header_flag & CRCFlag) == 0)
                        {
                            gzipHeaderSubstate = GZIPHeaderState.Done;
                            goto case GZIPHeaderState.Done;
                        }

                        bits = input.GetBits(8);     // ignore crc
                        if (bits < 0)
                        {
                            return false;
                        }

                        gzipHeaderSubstate = GZIPHeaderState.ReadingCRC16Part2;
                        goto case GZIPHeaderState.ReadingCRC16Part2;

                    case GZIPHeaderState.ReadingCRC16Part2:
                        bits = input.GetBits(8);     // ignore crc
                        if (bits < 0)
                        {
                            return false;
                        }

                        gzipHeaderSubstate = GZIPHeaderState.Done;
                        goto case GZIPHeaderState.Done;

                    case GZIPHeaderState.Done:
                        return true;
                    default:
                        Debug.Assert(false, "We should not reach unknown state!");
                        throw new InvalidDataException("SR.UnknownState");
                }
            }
        }
コード例 #10
0
ファイル: GZipDecoder.cs プロジェクト: 284247028/MvvmCross
        public bool ReadGzipFooter()
        {
            input.SkipToByteBoundary();
            if (gzipFooterSubstate == GZIPHeaderState.ReadingCRC)
            {
                while (loopCounter < 4)
                {
                    int bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return false;
                    }

                    gzipCrc32 |= ((uint)bits << (8 * loopCounter));
                    loopCounter++;
                }
                gzipFooterSubstate = GZIPHeaderState.ReadingFileSize;
                loopCounter = 0;

            }

            if (gzipFooterSubstate == GZIPHeaderState.ReadingFileSize)
            {
                if (loopCounter == 0)
                    gzipOutputStreamSize = 0;

                while (loopCounter < 4)
                {
                    int bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        return false;
                    }

                    gzipOutputStreamSize |= ((uint)bits << (8 * loopCounter));
                    loopCounter++;
                }
            }

            return true;
        }