예제 #1
0
        public static async Task ReadNormal()
        {
            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("normal.zip"), ZipTest.zfolder("normal"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("fake64.zip"), ZipTest.zfolder("small"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("empty.zip"), ZipTest.zfolder("empty"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("appended.zip"), ZipTest.zfolder("small"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("prepended.zip"), ZipTest.zfolder("small"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("emptydir.zip"), ZipTest.zfolder("emptydir"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("small.zip"), ZipTest.zfolder("small"), ZipArchiveMode.Read);

            if (Interop.IsWindows) // [ActiveIssue(846, PlatformID.AnyUnix)]
            {
                await ZipTest.IsZipSameAsDirAsync(
                    ZipTest.zfile("unicode.zip"), ZipTest.zfolder("unicode"), ZipArchiveMode.Read);
            }
        }
예제 #2
0
        public static async Task UnsupportedCompression()
        {
            //lzma compression method
            await UnsupportedCompressionRoutine(ZipTest.bad("lzma.zip"), true);

            await UnsupportedCompressionRoutine(ZipTest.bad("invalidDeflate.zip"), false);
        }
예제 #3
0
        public static async Task ReadNormal()
        {
            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("normal.zip"), ZipTest.zfolder("normal"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("fake64.zip"), ZipTest.zfolder("small"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("empty.zip"), ZipTest.zfolder("empty"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("appended.zip"), ZipTest.zfolder("small"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("prepended.zip"), ZipTest.zfolder("small"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("emptydir.zip"), ZipTest.zfolder("emptydir"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("small.zip"), ZipTest.zfolder("small"), ZipArchiveMode.Read);

            await ZipTest.IsZipSameAsDirAsync(
                ZipTest.zfile("unicode.zip"), ZipTest.zfolder("unicode"), ZipArchiveMode.Read);
        }
예제 #4
0
        public static async Task testFolder(String s)
        {
            var zs = new LocalMemoryStream();
            await ZipTest.CreateFromDir(ZipTest.zfolder(s), zs, ZipArchiveMode.Update);

            ZipTest.IsZipSameAsDir(zs.Clone(), ZipTest.zfolder(s), ZipArchiveMode.Read, false, false);
        }
예제 #5
0
 private static async Task TestStreamingRead(String zipFile, String directory)
 {
     using (var stream = await StreamHelpers.CreateTempCopyStream(zipFile))
     {
         Stream wrapped = new WrappedStream(stream, true, false, false, null);
         ZipTest.IsZipSameAsDir(wrapped, directory, ZipArchiveMode.Read, false, false);
         Assert.False(wrapped.CanRead, "Wrapped stream should be closed at this point"); //check that it was closed
     }
 }
예제 #6
0
        public static async Task testCreate(String folder, bool seekable)
        {
            using (var s = new MemoryStream())
            {
                var testStream = new WrappedStream(s, false, true, seekable, null);
                await ZipTest.CreateFromDir(ZipTest.zfolder(folder), testStream, ZipArchiveMode.Create);

                ZipTest.IsZipSameAsDir(s, ZipTest.zfolder(folder), ZipArchiveMode.Read, false, false);
            }
        }
예제 #7
0
        public static async Task ReadStreaming()
        {
            //don't include large, because that means loading the whole thing in memory

            await TestStreamingRead(ZipTest.zfile("normal.zip"), ZipTest.zfolder("normal"));
            await TestStreamingRead(ZipTest.zfile("fake64.zip"), ZipTest.zfolder("small"));
            await TestStreamingRead(ZipTest.zfile("unicode.zip"), ZipTest.zfolder("unicode"));
            await TestStreamingRead(ZipTest.zfile("empty.zip"), ZipTest.zfolder("empty"));
            await TestStreamingRead(ZipTest.zfile("appended.zip"), ZipTest.zfolder("small"));
            await TestStreamingRead(ZipTest.zfile("prepended.zip"), ZipTest.zfolder("small"));
            await TestStreamingRead(ZipTest.zfile("emptydir.zip"), ZipTest.zfolder("emptydir"));
        }
예제 #8
0
 public static async Task CompatibilityTests()
 {
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.compat("7zip.zip")), ZipTest.zfolder("normal"), ZipArchiveMode.Update, false, false);
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.compat("windows.zip")), ZipTest.zfolder("normalWithoutEmptyDir"), ZipArchiveMode.Update, true, false);
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.compat("dotnetzipstreaming.zip")), ZipTest.zfolder("normal"), ZipArchiveMode.Update, true, true);
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.compat("sharpziplib.zip")), ZipTest.zfolder("normalWithoutEmptyDir"), ZipArchiveMode.Update, true, true);
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.compat("xceedstreaming.zip")), ZipTest.zfolder("normal"), ZipArchiveMode.Update, true, true);
 }
예제 #9
0
 public static async Task CompatibilityTestsMsFiles()
 {
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.compat("excel.xlsx")), ZipTest.compat("excel"), ZipArchiveMode.Update, true, true);
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.compat("powerpoint.pptx")), ZipTest.compat("powerpoint"), ZipArchiveMode.Update, true, true);
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.compat("word.docx")), ZipTest.compat("word"), ZipArchiveMode.Update, true, true);
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.compat("silverlight.xap")), ZipTest.compat("silverlight"), ZipArchiveMode.Update, true, true);
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.compat("packaging.package")), ZipTest.compat("packaging"), ZipArchiveMode.Update, true, true);
 }
예제 #10
0
 public static async Task UpdateReadNormal()
 {
     ZipTest.IsZipSameAsDir(
         await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip")), ZipTest.zfolder("normal"), ZipArchiveMode.Update, false, false);
     ZipTest.IsZipSameAsDir(
         await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("fake64.zip")), ZipTest.zfolder("small"), ZipArchiveMode.Update, false, false);
     ZipTest.IsZipSameAsDir(
         await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("unicode.zip")), ZipTest.zfolder("unicode"), ZipArchiveMode.Update, false, false);
     ZipTest.IsZipSameAsDir(
         await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("empty.zip")), ZipTest.zfolder("empty"), ZipArchiveMode.Update, false, false);
     ZipTest.IsZipSameAsDir(
         await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("appended.zip")), ZipTest.zfolder("small"), ZipArchiveMode.Update, false, false);
     ZipTest.IsZipSameAsDir(
         await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("prepended.zip")), ZipTest.zfolder("small"), ZipArchiveMode.Update, false, false);
 }
예제 #11
0
 public static async Task ReadStreamOps()
 {
     using (ZipArchive archive = new ZipArchive(await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip")), ZipArchiveMode.Read))
     {
         foreach (ZipArchiveEntry e in archive.Entries)
         {
             using (Stream s = e.Open())
             {
                 Assert.True(s.CanRead, "Can read to read archive");
                 Assert.False(s.CanWrite, "Can't write to read archive");
                 Assert.False(s.CanSeek, "Can't seek on archive");
                 Assert.Equal(ZipTest.LengthOfUnseekableStream(s), e.Length); //"Length is not correct on unseekable stream"
             }
         }
     }
 }
예제 #12
0
        public static async Task ReadStreaming()
        {
            //don't include large, because that means loading the whole thing in memory

            await TestStreamingRead(ZipTest.zfile("normal.zip"), ZipTest.zfolder("normal"));
            await TestStreamingRead(ZipTest.zfile("fake64.zip"), ZipTest.zfolder("small"));

            if (Interop.IsWindows) // [ActiveIssue(846, PlatformID.AnyUnix)]
            {
                await TestStreamingRead(ZipTest.zfile("unicode.zip"), ZipTest.zfolder("unicode"));
            }
            await TestStreamingRead(ZipTest.zfile("empty.zip"), ZipTest.zfolder("empty"));
            await TestStreamingRead(ZipTest.zfile("appended.zip"), ZipTest.zfolder("small"));
            await TestStreamingRead(ZipTest.zfile("prepended.zip"), ZipTest.zfolder("small"));
            await TestStreamingRead(ZipTest.zfile("emptydir.zip"), ZipTest.zfolder("emptydir"));
        }
예제 #13
0
        public static async Task InvalidDates()
        {
            using (ZipArchive archive = new ZipArchive(await StreamHelpers.CreateTempCopyStream(
                                                           ZipTest.bad("invaliddate.zip")), ZipArchiveMode.Read))
            {
                Assert.Equal(new DateTime(1980, 1, 1, 0, 0, 0), archive.Entries[0].LastWriteTime.DateTime); //"Date isn't correct on invalid date"
            }

            using (ZipArchive archive = new ZipArchive(new MemoryStream(), ZipArchiveMode.Create))
            {
                ZipArchiveEntry entry = archive.CreateEntry("test");
                Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                            { entry.LastWriteTime = new DateTimeOffset(1979, 12, 3, 5, 6, 2, new TimeSpan()); }); //"should throw on bad date"
                Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                            { entry.LastWriteTime = new DateTimeOffset(2980, 12, 3, 5, 6, 2, new TimeSpan()); }); //"Should throw on bad date"
            }
        }
예제 #14
0
        public static async Task InvalidInstanceMethods()
        {
            Stream zipFile = await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip"));

            using (ZipArchive archive = new ZipArchive(zipFile, ZipArchiveMode.Update))
            {
                //non-existent entry
                Assert.True(null == archive.GetEntry("nonExistentEntry"));           //"Should return null on non-existent entry name"
                //null/empty string
                Assert.Throws <ArgumentNullException>(() => archive.GetEntry(null)); //"Should throw on null entry name"

                ZipArchiveEntry entry = archive.GetEntry("first.txt");

                //null/empty string
                Assert.Throws <ArgumentException>(() => archive.CreateEntry(""));       //"Should throw on empty entry name"
                Assert.Throws <ArgumentNullException>(() => archive.CreateEntry(null)); //"should throw on null entry name"
            }
        }
예제 #15
0
        public static async Task UpdateModeInvalidOperations()
        {
            using (LocalMemoryStream ms = await LocalMemoryStream.readAppFileAsync(ZipTest.zfile("normal.zip")))
            {
                ZipArchive target = new ZipArchive(ms, ZipArchiveMode.Update, true);

                ZipArchiveEntry edeleted = target.GetEntry("first.txt");

                Stream s = edeleted.Open();
                //invalid ops while entry open
                Assert.Throws <IOException>(() => edeleted.Open());
                Assert.Throws <InvalidOperationException>(() => { var x = edeleted.Length; });
                Assert.Throws <InvalidOperationException>(() => { var x = edeleted.CompressedLength; });
                Assert.Throws <IOException>(() => edeleted.Delete());
                s.Dispose();

                //invalid ops on stream after entry closed
                Assert.Throws <ObjectDisposedException>(() => s.ReadByte());

                Assert.Throws <InvalidOperationException>(() => { var x = edeleted.Length; });
                Assert.Throws <InvalidOperationException>(() => { var x = edeleted.CompressedLength; });

                edeleted.Delete();
                //invalid ops while entry deleted
                Assert.Throws <InvalidOperationException>(() => edeleted.Open());
                Assert.Throws <InvalidOperationException>(() => { edeleted.LastWriteTime = new DateTimeOffset(); });

                ZipArchiveEntry e = target.GetEntry("notempty/second.txt");

                target.Dispose();

                Assert.Throws <ObjectDisposedException>(() => { var x = target.Entries; });
                Assert.Throws <ObjectDisposedException>(() => target.CreateEntry("dirka"));
                Assert.Throws <ObjectDisposedException>(() => e.Open());
                Assert.Throws <ObjectDisposedException>(() => e.Delete());
                Assert.Throws <ObjectDisposedException>(() => { e.LastWriteTime = new DateTimeOffset(); });
            }
        }
예제 #16
0
        public static async Task UpdateAddFile()
        {
            //add file
            var testArchive = await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip"));

            using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true))
            {
                await updateArchive(archive, ZipTest.zmodified(Path.Combine("addFile", "added.txt")), "added.txt");
            }

            ZipTest.IsZipSameAsDir(testArchive, ZipTest.zmodified("addFile"), ZipArchiveMode.Read, false, false);

            //add file and read entries before
            testArchive = await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip"));

            using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true))
            {
                var x = archive.Entries;

                await updateArchive(archive, ZipTest.zmodified(Path.Combine("addFile", "added.txt")), "added.txt");
            }

            ZipTest.IsZipSameAsDir(testArchive, ZipTest.zmodified("addFile"), ZipArchiveMode.Read, false, false);


            //add file and read entries after
            testArchive = await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip"));

            using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true))
            {
                await updateArchive(archive, ZipTest.zmodified(Path.Combine("addFile", "added.txt")), "added.txt");

                var x = archive.Entries;
            }

            ZipTest.IsZipSameAsDir(testArchive, ZipTest.zmodified("addFile"), ZipArchiveMode.Read, false, false);
        }
예제 #17
0
 public static async Task UpdateReadTwice()
 {
     using (ZipArchive archive = new ZipArchive(await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("small.zip")), ZipArchiveMode.Update))
     {
         ZipArchiveEntry entry = archive.Entries[0];
         String          contents1, contents2;
         using (StreamReader s = new StreamReader(entry.Open()))
         {
             contents1 = s.ReadToEnd();
         }
         using (StreamReader s = new StreamReader(entry.Open()))
         {
             contents2 = s.ReadToEnd();
         }
         Assert.Equal(contents1, contents2);
     }
 }
예제 #18
0
        public static async Task ReadModeInvalidOpsTest()
        {
            ZipArchive      archive = new ZipArchive(await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip")), ZipArchiveMode.Read);
            ZipArchiveEntry e       = archive.GetEntry("first.txt");

            //should also do it on deflated stream

            //on archive
            Assert.Throws <NotSupportedException>(() => archive.CreateEntry("hi there")); //"Should not be able to create entry"

            //on entry
            Assert.Throws <NotSupportedException>(() => e.Delete());                             //"Should not be able to delete entry"
            //Throws<NotSupportedException>(() => e.MoveTo("dirka"));
            Assert.Throws <NotSupportedException>(() => e.LastWriteTime = new DateTimeOffset()); //"Should not be able to update time"

            //on stream
            Stream s = e.Open();

            Assert.Throws <NotSupportedException>(() => s.Flush());                   //"Should not be able to flush on read stream"
            Assert.Throws <NotSupportedException>(() => s.WriteByte(25));             //"should not be able to write to read stream"
            Assert.Throws <NotSupportedException>(() => s.Position = 4);              //"should not be able to seek on read stream"
            Assert.Throws <NotSupportedException>(() => s.Seek(0, SeekOrigin.Begin)); //"should not be able to seek on read stream"
            Assert.Throws <NotSupportedException>(() => s.SetLength(0));              //"should not be able to resize read stream"

            archive.Dispose();

            //after disposed
            Assert.Throws <ObjectDisposedException>(() => { var x = archive.Entries; });                //"Should not be able to get entries on disposed archive"
            Assert.Throws <NotSupportedException>(() => archive.CreateEntry("dirka"));                  //"should not be able to create on disposed archive"

            Assert.Throws <ObjectDisposedException>(() => e.Open());                                    //"should not be able to open on disposed archive"
            Assert.Throws <NotSupportedException>(() => e.Delete());                                    //"should not be able to delete on disposed archive"
            Assert.Throws <ObjectDisposedException>(() => { e.LastWriteTime = new DateTimeOffset(); }); //"Should not be able to update on disposed archive"

            Assert.Throws <NotSupportedException>(() => s.ReadByte());                                  //"should not be able to read on disposed archive"

            s.Dispose();
        }
예제 #19
0
 public static async Task StrangeFiles5()
 {
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.strange("filenameTimeAndSizesDifferentInLH.zip")), ZipTest.zfolder("verysmall"), ZipArchiveMode.Update, true, false);
 }
예제 #20
0
 public static async Task StrangeFiles4()
 {
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.strange("dataDescriptor.zip")), ZipTest.zfolder("normalWithoutBinary"), ZipArchiveMode.Update, true, false);
 }
예제 #21
0
 public static async Task StrangeFiles3()
 {
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.strange(Path.Combine("extradata", "zip64ThenExtraData.zip"))), ZipTest.zfolder("verysmall"), ZipArchiveMode.Update, false, false);
 }
예제 #22
0
 public static void UpdateEmptyEntry()
 {
     ZipTest.EmptyEntryTest(ZipArchiveMode.Update);
 }
예제 #23
0
        public static async Task ReadInterleaved()
        {
            using (ZipArchive archive = new ZipArchive(await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip"))))
            {
                ZipArchiveEntry e1 = archive.GetEntry("first.txt");
                ZipArchiveEntry e2 = archive.GetEntry("notempty/second.txt");

                //read all of e1 and e2's contents
                Byte[] e1readnormal  = new Byte[e1.Length];
                Byte[] e2readnormal  = new Byte[e2.Length];
                Byte[] e1interleaved = new Byte[e1.Length];
                Byte[] e2interleaved = new Byte[e2.Length];

                using (Stream e1s = e1.Open())
                {
                    ZipTest.ReadBytes(e1s, e1readnormal, e1.Length);
                }
                using (Stream e2s = e2.Open())
                {
                    ZipTest.ReadBytes(e2s, e2readnormal, e2.Length);
                }

                //now read interleaved, assume we are working with < 4gb files
                const Int32 bytesAtATime = 15;

                using (Stream e1s = e1.Open(), e2s = e2.Open())
                {
                    Int32 e1pos = 0;
                    Int32 e2pos = 0;

                    while (e1pos < e1.Length || e2pos < e2.Length)
                    {
                        if (e1pos < e1.Length)
                        {
                            Int32 e1bytesRead = e1s.Read(e1interleaved, e1pos,
                                                         bytesAtATime + e1pos > e1.Length ? (Int32)e1.Length - e1pos : bytesAtATime);
                            e1pos += e1bytesRead;
                        }

                        if (e2pos < e2.Length)
                        {
                            Int32 e2bytesRead = e2s.Read(e2interleaved, e2pos,
                                                         bytesAtATime + e2pos > e2.Length ? (Int32)e2.Length - e2pos : bytesAtATime);
                            e2pos += e2bytesRead;
                        }
                    }
                }

                //now compare to original read
                ZipTest.ArraysEqual <Byte>(e1readnormal, e1interleaved, e1readnormal.Length);
                ZipTest.ArraysEqual <Byte>(e2readnormal, e2interleaved, e2readnormal.Length);

                //now read one entry interleaved
                Byte[] e1selfInterleaved1 = new Byte[e1.Length];
                Byte[] e1selfInterleaved2 = new Byte[e2.Length];


                using (Stream s1 = e1.Open(), s2 = e1.Open())
                {
                    Int32 s1pos = 0;
                    Int32 s2pos = 0;

                    while (s1pos < e1.Length || s2pos < e1.Length)
                    {
                        if (s1pos < e1.Length)
                        {
                            Int32 s1bytesRead = s1.Read(e1interleaved, s1pos,
                                                        bytesAtATime + s1pos > e1.Length ? (Int32)e1.Length - s1pos : bytesAtATime);
                            s1pos += s1bytesRead;
                        }

                        if (s2pos < e1.Length)
                        {
                            Int32 s2bytesRead = s2.Read(e2interleaved, s2pos,
                                                        bytesAtATime + s2pos > e1.Length ? (Int32)e1.Length - s2pos : bytesAtATime);
                            s2pos += s2bytesRead;
                        }
                    }
                }

                //now compare to original read
                ZipTest.ArraysEqual <Byte>(e1readnormal, e1selfInterleaved1, e1readnormal.Length);
                ZipTest.ArraysEqual <Byte>(e1readnormal, e1selfInterleaved2, e1readnormal.Length);
            }
        }
예제 #24
0
        public static async Task UpdateModifications()
        {
            //delete and move
            var testArchive = await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip"));

            using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true))
            {
                ZipArchiveEntry toBeDeleted = archive.GetEntry("binary.wmv");
                toBeDeleted.Delete();
                toBeDeleted.Delete(); //delete twice should be okay
                ZipArchiveEntry moved = archive.CreateEntry("notempty/secondnewname.txt");
                ZipArchiveEntry orig  = archive.GetEntry("notempty/second.txt");
                using (Stream origMoved = orig.Open(), movedStream = moved.Open())
                {
                    origMoved.CopyTo(movedStream);
                }
                moved.LastWriteTime = orig.LastWriteTime;
                orig.Delete();
            }

            ZipTest.IsZipSameAsDir(testArchive, ZipTest.zmodified("deleteMove"), ZipArchiveMode.Read, false, false);

            //append
            testArchive = await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip"));

            using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true))
            {
                ZipArchiveEntry e = archive.GetEntry("first.txt");

                using (StreamWriter s = new StreamWriter(e.Open()))
                {
                    s.BaseStream.Seek(0, SeekOrigin.End);

                    s.Write("\r\n\r\nThe answer my friend, is blowin' in the wind.");
                }

                e.LastWriteTime = new DateTimeOffset(2010, 7, 7, 11, 57, 18, new TimeSpan(-7, 0, 0));
            }

            ZipTest.IsZipSameAsDir(testArchive, ZipTest.zmodified("append"), ZipArchiveMode.Read, false, false);

            //Overwrite file
            testArchive = await StreamHelpers.CreateTempCopyStream(ZipTest.zfile("normal.zip"));

            using (ZipArchive archive = new ZipArchive(testArchive, ZipArchiveMode.Update, true))
            {
                String          fileName = ZipTest.zmodified(Path.Combine("overwrite", "first.txt"));
                ZipArchiveEntry e        = archive.GetEntry("first.txt");

                var file = FileData.GetFile(fileName);
                e.LastWriteTime = file.LastModifiedDate;

                using (var stream = await StreamHelpers.CreateTempCopyStream(fileName))
                {
                    using (Stream es = e.Open())
                    {
                        es.SetLength(0);
                        stream.CopyTo(es);
                    }
                }
            }

            ZipTest.IsZipSameAsDir(testArchive, ZipTest.zmodified("overwrite"), ZipArchiveMode.Read, false, false);
        }
예제 #25
0
 public static async Task StrangeFiles1()
 {
     ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream(
                                ZipTest.strange(Path.Combine("extradata", "extraDataLHandCDentryAndArchiveComments.zip"))), ZipTest.zfolder("verysmall"), ZipArchiveMode.Update, false, false);
 }