public void ExtractEmptyDirectories() { string tempFilePath = GetTempFilePath(); Assert.IsNotNull(tempFilePath, "No permission to execute this test?"); string name = Path.Combine(tempFilePath, "x.zip"); EnsureTestDirectoryIsEmpty(tempFilePath); string targetDir = Path.Combine(tempFilePath, ZipTempDir + @"\floyd"); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fs = store.CreateFile(name)) { using (ZipOutputStream zOut = new ZipOutputStream(fs)) { zOut.PutNextEntry(new ZipEntry("floyd/")); } } IsolatedFastZip fastZip = new IsolatedFastZip(); fastZip.CreateEmptyDirectories = true; fastZip.ExtractZip(name, targetDir, "zz"); store.DeleteFile(name); Assert.IsTrue(Directory.Exists(targetDir), "Empty directory should be created"); } }
public void UnicodeText() { using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { IsolatedFastZip zippy = new IsolatedFastZip(); ZipEntryFactory factory = new ZipEntryFactory(); factory.IsUnicodeText = true; zippy.EntryFactory = factory; string tempFilePath = GetTempFilePath(); Assert.IsNotNull(tempFilePath, "No permission to execute this test?"); const string tempName1 = "a.dat"; string addFile = Path.Combine(tempFilePath, tempName1); MakeTempFile(addFile, 1); try { MemoryStream target = new MemoryStream(); zippy.CreateZip(target, tempFilePath, false, tempName1, null); // failing here in 4 MemoryStream archive = new MemoryStream(target.ToArray()); using (IsolatedZipFile z = new IsolatedZipFile(archive)) { Assert.AreEqual(1, z.Count); Assert.IsTrue(z[0].IsUnicodeText); } } finally { store.DeleteFile(addFile); } } }
public void Noid() { using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream fs = store.CreateFile("foo.txt")) { using (var writer = new StreamWriter(fs)) { writer.Write("Foo Bar FU!"); } } store.CreateDirectory("foobarfu"); string fooText = Guid.NewGuid().ToString(); using (var createdFile = store.CreateFile("foo.txt")) { using (var writer = new StreamWriter(createdFile)) { writer.Write(fooText); } } using (var createdFile = store.CreateFile("foobarfu\\foo.txt")) { using (var writer = new StreamWriter(createdFile)) { writer.Write(fooText); } } var factory = new IsolatedZipEntryFactory(); ZipEntry fentry = factory.MakeFileEntry("foo.txt"); ZipEntry dentry = factory.MakeDirectoryEntry("foobarfu"); using (var f = IsolatedZipFile.Create("foo.zip")) { f.BeginUpdate(); f.Add("foo.txt"); f.CommitUpdate(); } using (var f = new IsolatedZipFile("foo.zip")) { var entry = f.GetEntry("foo.txt"); string content = new StreamReader(f.GetInputStream(entry)).ReadToEnd(); Assert.AreEqual(fooText, content); } var fz = new IsolatedFastZip(); fz.CreateZip("fz.zip", "foobarfu", true, ""); } }
public void ExtractExceptions() { using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { IsolatedFastZip fastZip = new IsolatedFastZip(); string tempFilePath = GetTempFilePath(); Assert.IsNotNull(tempFilePath, "No permission to execute this test?"); string addFile = Path.Combine(tempFilePath, "test.zip"); try { fastZip.ExtractZip(addFile, @"z:\doesnt exist", null); } finally { store.DeleteFile(addFile); } } }
public void NonAsciiPasswords() { using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { const string tempName1 = "a.dat"; MemoryStream target = new MemoryStream(); string tempFilePath = GetTempFilePath(); Assert.IsNotNull(tempFilePath, "No permission to execute this test?"); string addFile = Path.Combine(tempFilePath, tempName1); MakeTempFile(addFile, 1); string password = "******"; try { IsolatedFastZip fastZip = new IsolatedFastZip(); fastZip.Password = password; fastZip.CreateZip(target, tempFilePath, false, @"a\.dat", null); // failing here in 4 MemoryStream archive = new MemoryStream(target.ToArray()); using (IsolatedZipFile zf = new IsolatedZipFile(archive)) { zf.Password = password; Assert.AreEqual(1, zf.Count); ZipEntry entry = zf[0]; Assert.AreEqual(tempName1, entry.Name); Assert.AreEqual(1, entry.Size); // TODO: Testing is not yet ported - Assert.IsTrue(zf.TestArchive(true)); Assert.IsTrue(entry.IsCrypted); } } finally { store.DeleteFile(tempName1); } } }