limit the usage of slow ReaderFactory into ".tar.xx" formats

This commit is contained in:
Paddy Xu
2017-06-04 13:38:11 +03:00
parent 792520a6ff
commit 86733a4d3d
2 changed files with 17 additions and 15 deletions

View File

@@ -79,21 +79,10 @@ namespace QuickLook.Plugin.ArchiveViewer
{ {
using (var stream = File.OpenRead(path)) using (var stream = File.OpenRead(path))
{ {
// https://github.com/adamhathcock/sharpcompress/blob/master/FORMATS.md says: // ReaderFactory is slow... so limit its usage
// The 7Zip format doesn't allow for reading as a forward-only stream so 7Zip is only supported through the Archive API string[] useReader = {".tar.gz", ".tgz", ".tar.bz2", ".tar.lz", ".tar.xz"};
if (Path.GetExtension(path).ToLower() == ".7z")
{
var archive = ArchiveFactory.Open(stream);
_type = archive.Type.ToString(); if (useReader.Any(i => path.EndsWith(i)))
var root = new ArchiveFileEntry(Path.GetFileName(path), true);
_fileEntries.Add("", root);
foreach (var entry in archive.Entries)
ProcessByLevel(entry);
}
else
{ {
var reader = ReaderFactory.Open(stream); var reader = ReaderFactory.Open(stream);
@@ -105,6 +94,18 @@ namespace QuickLook.Plugin.ArchiveViewer
while (reader.MoveToNextEntry()) while (reader.MoveToNextEntry())
ProcessByLevel(reader.Entry); ProcessByLevel(reader.Entry);
} }
else
{
var archive = ArchiveFactory.Open(stream);
_type = archive.Type.ToString();
var root = new ArchiveFileEntry(Path.GetFileName(path), true);
_fileEntries.Add("", root);
foreach (var entry in archive.Entries)
ProcessByLevel(entry);
}
} }
} }

View File

@@ -25,6 +25,7 @@ namespace QuickLook.Plugin.ArchiveViewer
case ".rar": case ".rar":
case ".zip": case ".zip":
case ".tar": case ".tar":
case ".tgz":
case ".gz": case ".gz":
case ".bz2": case ".bz2":
case ".lz": case ".lz":
@@ -39,7 +40,7 @@ namespace QuickLook.Plugin.ArchiveViewer
public void Prepare(string path, ContextObject context) public void Prepare(string path, ContextObject context)
{ {
context.PreferredSize = new Size {Width = 800, Height = 600}; context.PreferredSize = new Size {Width = 800, Height = 400};
} }
public void View(string path, ContextObject context) public void View(string path, ContextObject context)