Beispiel #1
0
        public void ValuesPreserved()
        {
            MemoryStream    ms     = new MemoryStream();
            TarOutputStream tarOut = new TarOutputStream(ms);

            DateTime modTime = DateTime.Now;

            TarEntry entry = TarEntry.CreateTarEntry("TestEntry");

            entry.GroupId        = 12;
            entry.UserId         = 14;
            entry.ModTime        = modTime;
            entry.UserName       = "******";
            entry.GroupName      = "GroupName";
            entry.TarHeader.Mode = 12345;

            tarOut.PutNextEntry(entry);
            tarOut.Close();

            MemoryStream ms2 = new MemoryStream();

            ms2.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
            ms2.Seek(0, SeekOrigin.Begin);

            TarInputStream tarIn     = new TarInputStream(ms2);
            TarEntry       nextEntry = tarIn.GetNextEntry();

            Assert.AreEqual(entry.TarHeader.Checksum, nextEntry.TarHeader.Checksum, "Checksum");

            Assert.IsTrue(nextEntry.Equals(entry), "Entries should be equal");
            Assert.IsTrue(nextEntry.TarHeader.Equals(entry.TarHeader), "Headers should match");

            // Tar only stores seconds
            DateTime truncatedTime = new DateTime(modTime.Year, modTime.Month, modTime.Day,
                                                  modTime.Hour, modTime.Minute, modTime.Second);

            Assert.AreEqual(truncatedTime, nextEntry.ModTime, "Modtimes should match");

            int entryCount = 0;

            while (nextEntry != null)
            {
                ++entryCount;
                nextEntry = tarIn.GetNextEntry();
            }

            Assert.AreEqual(1, entryCount, "Expected 1 entry");
        }