void Parse() { using (var stream = System.IO.File.OpenRead(Name.GetPath())) { var input = new ZipInputStream(stream); ZipEntry entry; while ((entry = input.GetNextEntry()) != null) { Trace.WriteLine("Reading Entry: " + entry.FileName); var name = entry.FileName.Split('/'); if (name.Length == 1) // a file { byte[] data = input.ReadToEnd(); Trace.WriteLine("Read: " + data.Length + " bytes"); var fn = FileName.GetFileName(this.Name, name[0]); _files.Add(name[0], new ZippedFile(fn, data)); } else { var first = name.First(); var parent = new ZippedDirectory(DirectoryName.GetDirectoryName(this.Name, first), this); _directories.Add(first, parent); var rest = name.Skip(1).Take(name.Length - 2); var queue = new Queue<string>(rest); foreach (var item in queue) { var dir = new ZippedDirectory(DirectoryName.GetDirectoryName(parent.Name, item), parent); parent = dir; } var file = name.Last(); byte[] data = input.ReadToEnd(); Trace.WriteLine("Read: " + data.Length + " bytes"); //neds to be added var zipfile = new ZippedFile(FileName.GetFileName(parent.Name, file), data); parent.AddFile(file, zipfile); } } } _parse = () => { }; }
void parseFile(ZipInputStream input,ZipEntry entry) { var name = entry.FileName.Split('/'); if (name.Length == 1) // a file { byte[] data = input.ReadToEnd(); Trace.WriteLine("Read: " + data.Length + " bytes"); var fn = FileName.GetFileName(Name, name[0]); AddFile(new ZippedFile(fn, data)); } else { var first = name.First(); var parent = new ZippedDirectory(DirectoryName.GetDirectoryName(Name, first), this); AddDirectory(parent); var rest = name.Skip(1).Take(name.Length - 2); var queue = new Queue<string>(rest); foreach (var item in queue) { var dir = new ZippedDirectory(DirectoryName.GetDirectoryName(parent.Name, item), parent); parent.AddDirectory(dir); parent = dir; } var file = name.Last(); byte[] data = input.ReadToEnd(); Trace.WriteLine("Read: " + data.Length + " bytes"); //neds to be added var zipfile = new ZippedFile(FileName.GetFileName(parent.Name, file), data); parent.AddFile(zipfile); } }