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); }
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 } }
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); } }
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); }
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); }
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); }
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); }
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); }
public static async Task StrangeFiles5() { ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream( ZipTest.strange("filenameTimeAndSizesDifferentInLH.zip")), ZipTest.zfolder("verysmall"), ZipArchiveMode.Update, true, false); }
public static async Task StrangeFiles4() { ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream( ZipTest.strange("dataDescriptor.zip")), ZipTest.zfolder("normalWithoutBinary"), ZipArchiveMode.Update, true, false); }
public static async Task StrangeFiles3() { ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream( ZipTest.strange(Path.Combine("extradata", "zip64ThenExtraData.zip"))), ZipTest.zfolder("verysmall"), ZipArchiveMode.Update, false, false); }
public static async Task StrangeFiles1() { ZipTest.IsZipSameAsDir(await StreamHelpers.CreateTempCopyStream( ZipTest.strange(Path.Combine("extradata", "extraDataLHandCDentryAndArchiveComments.zip"))), ZipTest.zfolder("verysmall"), ZipArchiveMode.Update, false, false); }