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(new PositioningStream(firstSevenZipArchiveEntry.OpenEntryStream())); break; default: FileSize = new FileInfo(filePath).Length; streamReader = new StreamReader(filePath); break; } CurrentFilePosition = 0; }
public override Stream GetStream(string name) { // will search .fnt file or image in here. var file = Path.HasExtension(name) ? name : $"{name}.bin"; ZipArchiveEntry entry = archive.Entries.SingleOrDefault(e => e.Key == file); if (entry == null) { throw new FileNotFoundException(); } // allow seeking MemoryStream copy = new MemoryStream(); using (Stream s = entry.OpenEntryStream()) s.CopyTo(copy); copy.Position = 0; return(copy); }
public static string GetMD5(this ZipArchiveEntry entry) { return(entry.OpenEntryStream().GetMD5()); }