/** * <param name="entry"></param> * <param name="localFilePath"></param> * <summary></summary> * * Should no longer be necessary if the ResourceGetter functionalities are working as intended. */ private void CopyRarEntryContent(Entry entry, string localFilePath) { RarArchiveEntry rae = (RarArchiveEntry)entry; using (var rarEntryStream = rae.OpenEntryStream()) { using (var targetFileStream = File.Create(localFilePath, (int)rarEntryStream.Length)) { rarEntryStream.CopyTo(targetFileStream); } } }
/** * <param name="xml_rarEntry"> * Rar entry holding the xml file to be processed. The parameter of the same name will be passed in from * GenerateObjectProperties(). * </param> * * <summary> * Use the Windows file api and Sharpcompress provided functionalities to copy the contents of the * rar entry into a temporary xml file to be extracted. * </summary> * * <returns>String path to temporary xml file</returns> */ private string CopyRaEntryToXMLFile(RarArchiveEntry xml_rarEntry) { string pathToTempFile = this.tempDir.Path + "/tempXml.xml"; using (var rarStream = xml_rarEntry.OpenEntryStream()) { using (var xmlStream = File.Create(pathToTempFile, (int)rarStream.Length)) { rarStream.CopyTo(xmlStream); } } return(pathToTempFile); }
/** * <summary> * Copies image from the Entry object as obtained by SharpCompress's RARArchive.Open() and RarArchive.Entries to an image file * in the application's local folder. This is done to allow the bitmap image class to access the image inside the rar directory * (could not figure out how to do it any other way :( ). * </summary> * <param name="entry">Entry: the items within the Compressed File as obtained by SharpCompress's read methods.</param> * <returns>String : the path to the image in the local directory</returns> */ private string CopyImageToLocalFolder(Entry entry) { string currentImagePath = this.GenerateImgPath(); RarArchiveEntry raentry = (RarArchiveEntry)entry; using (var raentryStream = raentry.OpenEntryStream()) { using (var imgFileStream = File.Create(currentImagePath, (int)raentryStream.Length)) { raentryStream.CopyTo(imgFileStream); } } return(currentImagePath); }
public SqlDumpReader(string filePath) { string fileExtension = Path.GetExtension(filePath).ToLower(); if (!SUPPORTED_DUMP_FILE_EXTENSIONS.Contains(fileExtension)) { throw new Exception($"{fileExtension} is not in the list of supported database dump file extensions."); } switch (fileExtension.ToLower()) { case ".zip": zipArchive = ZipArchive.Open(filePath); ZipArchiveEntry firstZipArchiveEntry = zipArchive.Entries.First(); FileSize = firstZipArchiveEntry.Size; streamReader = new StreamReader(firstZipArchiveEntry.OpenEntryStream()); break; case ".rar": rarArchive = RarArchive.Open(filePath); RarArchiveEntry firstRarArchiveEntry = rarArchive.Entries.First(); FileSize = firstRarArchiveEntry.Size; streamReader = new StreamReader(firstRarArchiveEntry.OpenEntryStream()); break; case ".gz": gZipArchive = GZipArchive.Open(filePath); GZipArchiveEntry firstGZipArchiveEntry = gZipArchive.Entries.First(); FileSize = firstGZipArchiveEntry.Size; streamReader = new StreamReader(firstGZipArchiveEntry.OpenEntryStream()); break; case ".7z": sevenZipArchive = SevenZipArchive.Open(filePath); SevenZipArchiveEntry firstSevenZipArchiveEntry = sevenZipArchive.Entries.First(); FileSize = firstSevenZipArchiveEntry.Size; streamReader = new StreamReader(new PositioningStream(firstSevenZipArchiveEntry.OpenEntryStream())); break; default: FileSize = new FileInfo(filePath).Length; streamReader = new StreamReader(filePath); break; } CurrentFilePosition = 0; }
public SqlDumpReader(string filePath) { string fileExtension = Path.GetExtension(filePath); switch (fileExtension.ToLower()) { case ".zip": zipArchive = ZipArchive.Open(filePath); ZipArchiveEntry firstZipArchiveEntry = zipArchive.Entries.First(); FileSize = firstZipArchiveEntry.Size; streamReader = new StreamReader(firstZipArchiveEntry.OpenEntryStream()); break; case ".rar": rarArchive = RarArchive.Open(filePath); RarArchiveEntry firstRarArchiveEntry = rarArchive.Entries.First(); FileSize = firstRarArchiveEntry.Size; streamReader = new StreamReader(firstRarArchiveEntry.OpenEntryStream()); break; case ".gz": gZipArchive = GZipArchive.Open(filePath); GZipArchiveEntry firstGZipArchiveEntry = gZipArchive.Entries.First(); FileSize = firstGZipArchiveEntry.Size; streamReader = new StreamReader(firstGZipArchiveEntry.OpenEntryStream()); break; case ".7z": sevenZipArchive = SevenZipArchive.Open(filePath); SevenZipArchiveEntry firstSevenZipArchiveEntry = sevenZipArchive.Entries.First(); FileSize = firstSevenZipArchiveEntry.Size; streamReader = new StreamReader(firstSevenZipArchiveEntry.OpenEntryStream()); break; default: FileSize = new FileInfo(filePath).Length; streamReader = new StreamReader(filePath); break; } CurrentFilePosition = 0; }