public static Stream[] GetFileStreams(string fromZip, string password, int[] list) { using (FileStream fs = File.OpenRead(fromZip)) { BlubbZipFile blubb = new BlubbZipFile(fs); blubb.Password = password; Stream[] streams = new Stream[list.Length]; int counter = 0; foreach (int index in list) { Stream s = blubb.GetInputStream(index); Stream writer = new MemoryStream(); byte[] data = new byte[4096]; int size = s.Read(data, 0, data.Length); while (size > 0) { writer.Write(data, 0, size); size = s.Read(data, 0, data.Length); } streams[counter++] = writer; } blubb.Close(); return(streams); } }
/// <summary> /// Extract the contents of a blubb file. /// </summary> /// <param name="blubbFileName">The blubb file to extract from.</param> /// <param name="targetDirectory">The directory to save extracted information in.</param> /// <param name="overwrite">The style of <see cref="Overwrite">overwriting</see> to apply.</param> /// <param name="confirmDelegate">A delegate to invoke when confirming overwriting.</param> /// <param name="fileFilter">A filter to apply to files.</param> /// <param name="directoryFilter">A filter to apply to directories.</param> /// <param name="restoreDateTime">Flag indicating wether to restore the date and time for extracted files.</param> public void ExtractBlubb(string blubbFileName, string targetDirectory, Overwrite overwrite, ConfirmOverwriteDelegate confirmDelegate, string fileFilter, string directoryFilter, bool restoreDateTime) { if ((overwrite == Overwrite.Prompt) && (confirmDelegate == null)) { throw new ArgumentNullException("confirmDelegate"); } continueRunning_ = true; overwrite_ = overwrite; confirmDelegate_ = confirmDelegate; extractNameTransform_ = new WindowsNameTransform(targetDirectory); fileFilter_ = new NameFilter(fileFilter); directoryFilter_ = new NameFilter(directoryFilter); restoreDateTimeOnExtract_ = restoreDateTime; using (blubbFile_ = new BlubbZipFile(blubbFileName)) { #if !NETCF_1_0 if (password_ != null) { blubbFile_.Password = password_; } #endif System.Collections.IEnumerator enumerator = blubbFile_.GetEnumerator(); while (continueRunning_ && enumerator.MoveNext()) { BlubbZipEntry entry = (BlubbZipEntry)enumerator.Current; if (entry.IsFile) { // TODO Path.GetDirectory can fail here on invalid characters. if (directoryFilter_.IsMatch(Path.GetDirectoryName(entry.Name)) && fileFilter_.IsMatch(entry.Name)) { ExtractEntry(entry); } } else if (entry.IsDirectory) { if (directoryFilter_.IsMatch(entry.Name) && CreateEmptyDirectories) { ExtractEntry(entry); } } else { // Do nothing for volume labels etc... } } } }
public static Stream GetFileStream(string fromZip, string password, int index) { using (FileStream fs = File.OpenRead(fromZip)) { BlubbZipFile blubb = new BlubbZipFile(fs); blubb.Password = password; Stream s = blubb.GetInputStream(index); Stream writer = new MemoryStream(); byte[] data = new byte[4096]; int size = s.Read(data, 0, data.Length); while (size > 0) { writer.Write(data, 0, size); size = s.Read(data, 0, data.Length); } blubb.Close(); return(writer); } }
public static MemoryStream FetchFromFile(string blubbzipFilePath, string blubbzipPassword, int entryIndex) { using (FileStream fs = File.OpenRead(blubbzipFilePath)) { BlubbZipFile blubb = new BlubbZipFile(fs); blubb.Password = blubbzipPassword; Stream s = blubb.GetInputStream(entryIndex); MemoryStream Writer = new MemoryStream(); byte[] data = new byte[4096]; int size = s.Read(data, 0, data.Length); while (size > 0) { Writer.Write(data, 0, size); size = s.Read(data, 0, data.Length); } blubb.Close(); return(Writer); } }
public static void FetchAllFromFile(string fileName, string password, EBlubbZipHelperLoadType loadType, out Dictionary <int, Stream> streamList, out Dictionary <int, string> fileList, out Dictionary <int, BlubbZipEntry> entryList) { fileList = new Dictionary <int, string>(); streamList = new Dictionary <int, Stream>(); entryList = new Dictionary <int, BlubbZipEntry>(); if (File.Exists(fileName) == false) { throw new Exception("File not Found!\n" + fileName); } using (FileStream fs = File.OpenRead(fileName)) { BlubbZipFile blubb = new BlubbZipFile(fs); blubb.Password = password; for (int cz = 0; cz < blubb.Count; cz++) { if (blubb[cz].IsFile == false) { continue; } if ((loadType & EBlubbZipHelperLoadType.Streams) > 0) { streamList.Add(cz, blubb.GetInputStream(cz)); } if ((loadType & EBlubbZipHelperLoadType.FileList) > 0) { fileList.Add(cz, blubb[cz].Name.ToString(CultureInfo.InvariantCulture).Replace("/", @"\")); } if ((loadType & EBlubbZipHelperLoadType.Entrys) > 0) { entryList.Add(cz, blubb[cz].Clone() as BlubbZipEntry); } } blubb.Close(); } }
public static void FetchAllFromFile(string blubbzipFilePath, string blubbzipPassword, EFastBlubbZipLoadType loadType, out Dictionary <int, Stream> StreamList, out Dictionary <int, string> FileList, out Dictionary <int, BlubbZipEntry> EntryList) { FileList = new Dictionary <int, string>(); StreamList = new Dictionary <int, Stream>(); EntryList = new Dictionary <int, BlubbZipEntry>(); if (File.Exists(blubbzipFilePath) == false) { throw new Exception("File not Found!\n" + blubbzipFilePath); } using (FileStream fs = File.OpenRead(blubbzipFilePath)) { BlubbZipFile blubb = new BlubbZipFile(fs); blubb.Password = blubbzipPassword; for (int cz = 0; cz < blubb.Count; cz++) { if (blubb[cz].IsFile == false) { continue; } if ((loadType & EFastBlubbZipLoadType.Streams) > 0) { StreamList.Add(cz, blubb.GetInputStream(cz)); } if ((loadType & EFastBlubbZipLoadType.FileList) > 0) { FileList.Add(cz, blubb[cz].Name.ToString().Replace("/", @"\")); } if ((loadType & EFastBlubbZipLoadType.Entrys) > 0) { EntryList.Add(cz, blubb[cz].Clone() as BlubbZipEntry); } } blubb.Close(); } }