ICSharpCode.SharpZipLib.Zip.ZipExtraData.AddLeInt C# (CSharp) Method

AddLeInt() public method

Add an integer value in little endian order to the pending new entry.
public AddLeInt ( int toAdd ) : void
toAdd int The data to add.
return void
        public void AddLeInt(int toAdd) {
            unchecked {
                AddLeShort((short)toAdd);
                AddLeShort((short)(toAdd>>16));
            }
        }

Usage Example

示例#1
0
        public void PasswordCheckingWithDateInExtraData()
        {
            MemoryStream ms = new MemoryStream();
            DateTime checkTime = new DateTime(2010, 10, 16, 0, 3, 28);

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

                ZipExtraData zed = new ZipExtraData();

                zed.StartNewEntry();

                zed.AddData(1);

                TimeSpan delta = checkTime.ToUniversalTime() - new System.DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime();
                int 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();
                byte theByte = (byte)zis.ReadByte();
                Assert.AreEqual(54, theByte);
                Assert.AreEqual(-1, zis.ReadByte());
                Assert.AreEqual(checkTime, uno.DateTime);
            }
        }