コード例 #1
0
ファイル: VcdiffDecoder.cs プロジェクト: mb3m/vcdifflibrary
        /// <summary>
        /// Reads the custom code table, if there is one
        /// </summary>
        private void ReadCodeTable()
        {
            // The length given includes the nearSize and sameSize bytes
            var compressedTableLength = IOUtils.ReadBigEndian7BitEncodedInt(delta) - 2;

            var nearSize = IOUtils.CheckedReadByte(delta);
            var sameSize = IOUtils.CheckedReadByte(delta);

            var compressedTableData = IOUtils.CheckedReadBytes(delta, compressedTableLength);

            var defaultTableData = CodeTable.Default.GetBytes();

            var decompressedTableData = new byte[CodeTable.TableSize];

            using (var tableOriginal = new MemoryStream(defaultTableData, false))
                using (var tableDelta = new MemoryStream(compressedTableData, false))
                    using (var tableOutput = new MemoryStream(decompressedTableData, true))
                    {
                        var innerDecoder = new VcdiffDecoder(tableOriginal, tableDelta, tableOutput);
                        innerDecoder.Decode();

                        if (tableOutput.Position != CodeTable.TableSize)
                        {
                            throw new VcdiffFormatException("Compressed code table was incorrect size");
                        }
                    }

            codeTable = new CodeTable(decompressedTableData);
            cache     = new AddressCache(nearSize, sameSize);
        }
コード例 #2
0
ファイル: VcdiffDecoder.cs プロジェクト: mb3m/vcdifflibrary
        private void ReadHeader()
        {
            var header = IOUtils.CheckedReadBytes(delta, 4);

            if (header[0] != 0xd6 || header[1] != 0xc3 || header[2] != 0xc4)
            {
                throw new VcdiffFormatException("Invalid VCDIFF header in delta stream, should start with 0xd6c3c4");
            }

            if (header[3] != 0)
            {
                throw new VcdiffFormatException("Only version 0 delta stream are supported by this version");
            }

            // Load the header indicator
            var hdrIndicator = IOUtils.CheckedReadByte(delta);

            if ((hdrIndicator & VCD_MASK) != 0)
            {
                throw new VcdiffFormatException("Invalid header indicator - only bits 1 and 2 can be set.");
            }

            if ((hdrIndicator & VCD_DECOMPRESS) != 0)
            {
                throw new VcdiffFormatException("This implementation does not support delta stream with secondary compressors");
            }

            if ((hdrIndicator & VCD_CODETABLE) != 0)
            {
                ReadCodeTable();
            }
            else
            {
                cache = new AddressCache(4, 3);
            }
        }