public static bool DownloadFileFromZipURL(string ZipURL, string FilePathInZip, string LocalPath) { if (!isURLValid(ZipURL)) { return(false); } bool ret = false; RemoteZipFile file = new RemoteZipFile(); if (file.Load(ZipURL)) { try { IEnumerator enumerator = file.GetEnumerator(); while (enumerator.MoveNext()) { ZipEntry current = (ZipEntry)enumerator.Current; if (current.Name == FilePathInZip) { FileStream output = new FileStream(LocalPath, FileMode.OpenOrCreate, FileAccess.ReadWrite); CopyStream(file.GetInputStream(current), output); output.Close(); ret = true; } } if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } } catch (Exception) { } } return(ret); }
public List <string> LoadFile(string Url) { if (zip.Load(Url)) { foreach (ZipEntry zipe in zip) { zipedFileList.Add(zipe.Name); InfoAboutZip ZipInfo = new InfoAboutZip(); ZipInfo.Name = zipe.Name; ZipInfo.ZipFileName = Url; ZipInfo.Index = zipe.ZipFileIndex; } } return(zipedFileList); }
public static void catchemall(string url, string remotepath, string localpath) { /* Checking if local file exists */ if (File.Exists(localpath)) { File.Delete(localpath); } /* creating local file */ File.Create(localpath).Dispose(); RemoteZipFile zip = new RemoteZipFile(); if (zip.Load(url) == false) { Console.WriteLine("ERROR: Wasn't able to map the remote zip"); Environment.Exit(1); } Console.WriteLine("Loaded URL: " + url); int itemscount = 0; foreach (ZipEntry zipe in zip) { //Console.WriteLine(zipe.ToString()); <- this prints all zip files (could be helpful for a --list argument) if (zipe.ToString() == remotepath) { Console.WriteLine("Found remote file: " + zipe.ToString()); break; } itemscount++; } ZipEntry zipee = zip[itemscount]; Stream os = File.Open(localpath, FileMode.Open); Stream s = zip.GetInputStream(zipee); byte[] bb = new byte[65536]; try { while (true) { int r = s.Read(bb, 0, bb.Length); if (r <= 0) { break; } os.Write(bb, 0, r); } } catch (Exception ee) { Console.WriteLine("Unknown error: " + ee); } os.Close(); s.Close(); }