Exemple #1
0
        private static DateTime ReadLastModifiedTime(Core.Utility.BinaryReader reader, ref int bytesRead)
        {
            var lastModifiedTime    = DateTime.MinValue;
            var modifiedTimeUnixUtc = reader.ReadUInt32();

            if (modifiedTimeUnixUtc != 0)
            {
                var epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                lastModifiedTime = epoch.AddSeconds(modifiedTimeUnixUtc);
            }
            bytesRead += sizeof(uint);
            return(lastModifiedTime);
        }
Exemple #2
0
        private static long FindNextEntry(Core.Utility.BinaryReader reader, GZipMemberEntry currentEntry)
        {
            var foundMagic          = false;
            var positionOfNextEntry = -1L;

            try
            {
                var magic = reader.ReadByte();
                while (true)
                {
                    if (magic == MagicIdentifier[0])
                    {
                        magic = reader.ReadByte();
                        if (magic == MagicIdentifier[1])
                        {
                            foundMagic = true;
                            break;
                        }
                    }
                    else
                    {
                        magic = reader.ReadByte();
                    }
                }
            }
            catch (EndOfStreamException)
            {
                positionOfNextEntry = reader.BaseStream.Length;
            }
            catch (IOException)
            {
            }

            if (foundMagic || (positionOfNextEntry == reader.BaseStream.Length))
            {
                // go back 4 (CRC32) + 4 (size mod 2^32) [+ 2 (magic)]
                var offset = sizeof(uint) + sizeof(int);
                var origin = SeekOrigin.End;
                if (foundMagic)
                {
                    offset += MagicIdentifier.Length;
                    origin  = SeekOrigin.Current;
                }
                reader.BaseStream.Seek(-offset, origin);
                currentEntry.Crc32   = reader.ReadUInt32();
                currentEntry._length = reader.ReadInt32();
                positionOfNextEntry  = reader.BaseStream.Position;
            }

            return(positionOfNextEntry);
        }
Exemple #3
0
        /// <inheritdoc />
        /// <remarks>The precondition here is that the reader is positioned immediately after the LUIGI block type value.</remarks>
        public override int Deserialize(Core.Utility.BinaryReader reader)
        {
            Length = reader.ReadUInt16();
            var bytesRead = PayloadLengthSize;

            HeaderCrc  = reader.ReadByte();
            bytesRead += HeaderChecksumSize;
            ValidateHeaderCrc();

            if (Length > 0)
            {
                PayloadCrc = reader.ReadUInt32();
                bytesRead += PayloadChecksumSize;
                bytesRead += DeserializePayload(reader);
            }
            return(bytesRead);
        }