Пример #1
0
        public void PasswordCheckingWithDateInExtraData()
        {
            var ms        = new MemoryStream();
            var checkTime = new DateTimeOffset(2010, 10, 16, 0, 3, 28, new TimeSpan(1, 0, 0));

            using (ZipOutputStream zos = new ZipOutputStream(ms))
            {
                zos.IsStreamOwner = false;
                zos.Password      = "******";
                var ze = new ZipEntry("uno");
                ze.DateTime = new DateTime(1998, 6, 5, 4, 3, 2);

                var zed = new ZipExtraData();

                zed.StartNewEntry();

                zed.AddData(1);

                TimeSpan delta   = checkTime.UtcDateTime - new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime();
                var      seconds = (int)delta.TotalSeconds;
                zed.AddLeInt(seconds);
                zed.AddNewEntry(0x5455);

                ze.ExtraData = zed.GetEntryData();
                zos.PutNextEntry(ze);
                zos.WriteByte(54);
            }

            ms.Position = 0;
            using (ZipInputStream zis = new ZipInputStream(ms))
            {
                zis.Password = "******";
                ZipEntry uno     = zis.GetNextEntry();
                var      theByte = (byte)zis.ReadByte();
                Assert.AreEqual(54, theByte);
                Assert.AreEqual(-1, zis.ReadByte());                 // eof
                Assert.AreEqual(checkTime.DateTime, uno.DateTime);
            }
        }
Пример #2
0
        public void PasswordCheckingWithDateInExtraData()
        {
            var ms = new MemoryStream();
            var checkTime = new DateTime(2010, 10, 16, 0, 3, 28);

            using (var zos = new ZipOutputStream(ms))
            {
                zos.IsStreamOwner = false;
                zos.Password = "******";
                var ze = new ZipEntry("uno");
                ze.DateTime = new DateTime(1998, 6, 5, 4, 3, 2);

                var zed = new ZipExtraData();

                zed.StartNewEntry();

                zed.AddData(1);

                var delta = checkTime.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime();
                var seconds = (int) delta.TotalSeconds;
                zed.AddLeInt(seconds);
                zed.AddNewEntry(0x5455);

                ze.ExtraData = zed.GetEntryData();
                zos.PutNextEntry(ze);
                zos.WriteByte(54);
            }

            ms.Position = 0;
            using (var zis = new ZipInputStream(ms))
            {
                zis.Password = "******";
                var uno = zis.GetNextEntry();
                var theByte = (byte) zis.ReadByte();
                Assert.AreEqual(54, theByte);
                Assert.AreEqual(-1, zis.ReadByte());
                Assert.AreEqual(checkTime, uno.DateTime);
            }
        }