Beispiel #1
0
 public ZipDirectory(ZipFileSystem fileSystem, LayeredNodeAddress address, ZLib.ZipEntry zipEntry)
     : base(fileSystem, address)
 {
     ((IZipNode)(this)).SetZipEntry(zipEntry);
 }
		public ZipFile(ZipFileSystem fileSystem, LayeredNodeAddress address, ZLib.ZipEntry zipEntry)
			: base(address, fileSystem)
		{
			((IZipNode)this).SetZipEntry(zipEntry);
		}
		public void Test_Walk_Zip_Directory()
		{
			using (var zfs = new ZipFileSystem(this.WorkingDirectory.ResolveFile("TestWalkZipDir.zip")))
			{
				const int limit = 100;
				int count = 0;
				var entries = new List<INode>();
				foreach (var entry in zfs.RootDirectory.Walk())
				{
					entries.Add(entry);
					if (++count > limit)
						Assert.Fail("Infinite loop when walking zip directory");
				}
				Assert.AreEqual(5, entries.Count);
				Assert.AreEqual(1, entries.Count(x =>
					x.Name == "sample" &&
					x.Address.AbsolutePath == "/sample" &&
					x.NodeType == NodeType.Directory));
				Assert.AreEqual(1, entries.Count(x =>
					x.Name == "TextFile2.txt" &&
					x.Address.AbsolutePath == "/sample/TextFile2.txt" &&
					x.NodeType == NodeType.File));
				Assert.AreEqual(1, entries.Count(x =>
					x.Name == "data" &&
					x.Address.AbsolutePath == "/sample/data" &&
					x.NodeType == NodeType.Directory));
				Assert.AreEqual(1, entries.Count(x =>
					x.Name == "DataFile1.xml" &&
					x.Address.AbsolutePath == "/sample/data/DataFile1.xml" &&
					x.NodeType == NodeType.File));
				Assert.AreEqual(1, entries.Count(x =>
					x.Name == "TextFile1.txt" &&
					x.Address.AbsolutePath == "/sample/data/TextFile1.txt" &&
					x.NodeType == NodeType.File));
			}
		}
		public void Test_Create_PasswordProtected_ZipFileSystem_And_Write_Files()
		{
			using (var fileSystem = ZipFileSystem.CreateZipFile(FileSystemManager.Default.ResolveFile("temp:///TestZipFile2.zip"), this.WorkingDirectory.ResolveDirectory("Directory1"), FileSystemOptions.Default.AddVariables(new { ZipPassword = "******" })))
			{
				var fileContents = fileSystem.ResolveFile("SubDirectory1/A.csv").GetContent().GetReader().ReadToEnd();

				Assert.AreEqual("A.csv", fileContents);

				var newFile = fileSystem.ResolveFile("SubDirectory1/B.txt");

				newFile.ParentDirectory.Create();

				Assert.IsFalse(newFile.Exists);

				using (var writer = newFile.GetContent().GetWriter(Encoding.UTF8))
				{
					writer.Write("B.txt");
				}

				Assert.IsTrue(newFile.Exists);
			}

			var fileContents2 = FileSystemManager.Default.ResolveFile("zip://[temp:///TestZipFile2.zip?ZipPassword=pass123]/SubDirectory1/A.csv").GetContent().GetReader().ReadToEnd();
			
			Console.WriteLine(fileContents2);

			FileSystemManager.Default.ResolveFileSystem("zip://[temp:///TestZipFile2.zip?ZipPassword=pass123]").Close();
			
			var fileContents3 = new ZipFileSystem(FileSystemManager.Default
				.ResolveFile("temp:///TestZipFile2.zip"), FileSystemOptions.Default.AddVariables(new { ZipPassword = "******" }))
				.ResolveFile("SubDirectory1/A.csv")
				.GetContent().GetReader().ReadToEnd();

			Console.WriteLine(fileContents3);
		}
 public ZipFile(ZipFileSystem fileSystem, LayeredNodeAddress address, ZLib.ZipEntry zipEntry)
     : base(address, fileSystem)
 {
     ((IZipNode)this).SetZipEntry(zipEntry);
 }
		public ZipDirectory(ZipFileSystem fileSystem, LayeredNodeAddress address, ZLib.ZipEntry zipEntry)
			: base(fileSystem, address)
		{
			((IZipNode)(this)).SetZipEntry(zipEntry);
		}