Exemple #1
0
            public void Parse(Stream hs)
            {
                PackPos        = hs.ReadDecodedUInt64();
                NumPackStreams = hs.ReadDecodedUInt64();
                Sizes          = new UInt64[NumPackStreams­];
                Digests        = new Digests(NumPackStreams);
                while (true)
                {
                    PropertyID propertyID = GetPropertyID(this, hs);
                    switch (propertyID)
                    {
                    case PropertyID.kSize:
                        for (ulong i = 0; i < NumPackStreams; ++i)
                        {
                            Sizes[i] = hs.ReadDecodedUInt64();
                        }
                        break;

                    case PropertyID.kCRC:
                        Digests.Parse(hs);
                        break;

                    case PropertyID.kEnd:
                        return;

                    default:
                        throw new NotImplementedException(propertyID.ToString());
                    }
                }
            }
Exemple #2
0
            public void Parse(Stream hs)
            {
                PropertyID propertyID = GetPropertyID(this, hs);

                // Number of UnPack Streams per Folder

                if (propertyID == PropertyID.kNumUnPackStream)
                {
                    NumUnPackStreamsInFolders = new UInt64[unPackInfo.NumFolders];
                    NumUnPackStreamsTotal     = 0;
                    for (ulong i = 0; i < unPackInfo.NumFolders; ++i)
                    {
                        NumUnPackStreamsTotal += NumUnPackStreamsInFolders[i] = hs.ReadDecodedUInt64();
                    }

                    propertyID = GetPropertyID(this, hs);
                }
                else // If no records, assume `1` output stream per folder
                {
                    NumUnPackStreamsInFolders = Enumerable.Repeat((UInt64)1, (int)unPackInfo.NumFolders).ToArray();
                    NumUnPackStreamsTotal     = unPackInfo.NumFolders;
                }

                // UnPackSizes

                UnPackSizes = new List <UInt64>();
                if (propertyID == PropertyID.kSize)
                {
                    for (ulong i = 0; i < unPackInfo.NumFolders; ++i)
                    {
                        UInt64 num = NumUnPackStreamsInFolders[i];
                        if (num == 0)
                        {
                            continue;
                        }

                        UInt64 sum = 0;
                        for (ulong j = 1; j < num; ++j)
                        {
                            UInt64 size = hs.ReadDecodedUInt64();
                            sum += size;
                            UnPackSizes.Add(size);
                        }
                        UnPackSizes.Add(unPackInfo.Folders[i].GetUnPackSize() - sum);
                    }

                    propertyID = GetPropertyID(this, hs);
                }
                else // If no records, assume one unpack size per folder
                {
                    for (ulong i = 0; i < unPackInfo.NumFolders; ++i)
                    {
                        ulong num = NumUnPackStreamsInFolders[i];
                        if (num > 1)
                        {
                            throw new SevenZipException($"Invalid number of UnPackStreams `{num}` in Folder # `{i}`.");
                        }
                        if (num == 1)
                        {
                            UnPackSizes.Add(unPackInfo.Folders[i].GetUnPackSize());
                        }
                    }
                }

                // Digests [Number of Unknown CRCs]

                UInt64 numDigests = 0;

                for (UInt64 i = 0; i < unPackInfo.NumFolders; ++i)
                {
                    UInt64 numSubStreams = NumUnPackStreamsInFolders[i];
                    if (numSubStreams > 1 || unPackInfo.Folders[i].UnPackCRC == null)
                    {
                        numDigests += numSubStreams;
                    }
                }

                if (propertyID == PropertyID.kCRC)
                {
                    Digests = new Digests(numDigests);
                    Digests.Parse(hs);

                    propertyID = GetPropertyID(this, hs);
                }

                if (propertyID != PropertyID.kEnd)
                {
                    throw new SevenZipException("Expected `kEnd` property ID.");
                }
            }
Exemple #3
0
            public void Parse(Stream hs)
            {
                ExpectPropertyID(this, hs, PropertyID.kFolder);

                // Folders

                NumFolders = hs.ReadDecodedUInt64();
                External   = hs.ReadByteThrow();
                switch (External)
                {
                case 0:
                    Folders = new Folder[NumFolders];
                    for (ulong i = 0; i < NumFolders; ++i)
                    {
                        Folders[i] = new Folder();
                        Folders[i].Parse(hs);
                    }
                    break;

                case 1:
                    DataStreamsIndex = hs.ReadDecodedUInt64();
                    break;

                default:
                    throw new SevenZipException("External value must be `0` or `1`.");
                }

                ExpectPropertyID(this, hs, PropertyID.kCodersUnPackSize);

                // CodersUnPackSize (data stored in `Folder.UnPackSizes`)

                for (ulong i = 0; i < NumFolders; ++i)
                {
                    Folders[i].UnPackSizes = new UInt64[Folders[i].NumOutStreamsTotal];
                    for (ulong j = 0; j < Folders[i].NumOutStreamsTotal; ++j)
                    {
                        Folders[i].UnPackSizes[j] = hs.ReadDecodedUInt64();
                    }
                }

                // Optional: UnPackDigests (data stored in `Folder.UnPackCRC`)

                PropertyID propertyID = GetPropertyID(this, hs);

                var UnPackDigests = new Digests(NumFolders);

                if (propertyID == PropertyID.kCRC)
                {
                    UnPackDigests.Parse(hs);
                    propertyID = GetPropertyID(this, hs);
                }
                for (ulong i = 0; i < NumFolders; ++i)
                {
                    if (UnPackDigests.Defined(i))
                    {
                        Folders[i].UnPackCRC = UnPackDigests.CRCs[i];
                    }
                }

                // end of UnPackInfo

                if (propertyID != PropertyID.kEnd)
                {
                    throw new SevenZipException("Expected kEnd property.");
                }
            }