我们目前正在使用压缩ICsharpCode.SharpZipLib库的GZipOutputStream类.我们从一个线程做到这一点.
我想将输入数据流拆分为块并并行压缩它们.我担心这个库可能有一些静态内部将被多个线程覆盖,因此破坏了生成的流.
任何想法将不胜感激.
我正在尝试将 tar.gz 解压缩到一个 zip 中,但我不能
\n\n它向我显示错误 \xe2\x80\x9ccannot findcentraldirectory\xe2\x80\x9d 并且我不\xe2\x80\x99t 不知道该怎么做。
\n\n首先,我将 zip 解压到临时文件夹上,然后在该文件夹上搜索 .tar.gz 并尝试解压,但因该错误而崩溃,但我可以使用 winrar 应用程序打开它,.tar.gz 有一些文件夹和一些里面的文件。
\n\n这是我的代码:
\n\nvar trash = Path.Combine(_temporalPath, "Trash");\n try\n {\n var zip = new FastZip();\n Directory.CreateDirectory(trash);\n zip.ExtractZip(_origin, trash, "");\n var gzip = Directory.GetFiles(trash, "*.tar.gz")[0];\n zip.ExtractZip(gzip, trash, FastZip.Overwrite.Always.ToString());\n File.Delete(gzip);\n }\n catch (Exception)\n {\n //IGNORE\n }\nRun Code Online (Sandbox Code Playgroud)\n\n我搜索信息,但只找到解压一个文件。\n在此处输入图像描述
\n\n我需要的是打开 tar.gz 并从里面获取文件。
\n每当我尝试获取文件时,输入流的长度(s.Length)总是为零,我做错了什么?ZipEntry是有效的,具有适当的文件大小等.
这是我使用的代码:
public static byte[] GetFileFromZip(string zipPath, string fileName)
{
byte[] ret = null;
ZipFile zf = new ZipFile(zipPath);
ZipEntry ze = zf.GetEntry(fileName);
if (ze != null)
{
Stream s = zf.GetInputStream(ze);
ret = new byte[s.Length];
s.Read(ret, 0, ret.Length);
}
return ret;
}
Run Code Online (Sandbox Code Playgroud) 我的Windows Phone 7项目中有一个zip文件.我已将Build Action to Content和Copy to output目录设置为Always.zip文件包含文件夹结构.我希望这完全复制,因为它在我的电话项目中.我正在使用SharpZipLib.这是代码: -
Stream stremInfo = Application.GetResourceStream(new Uri("xip.zip", UriKind.Relative)).Stream;
new FastZip(). ExtractZip(stremInfo,
"",FastZip.Overwrite.Always,null,null,null,true,true);
Run Code Online (Sandbox Code Playgroud)
但是,在调用ExractZip时出现错误.我得到的例外是" MethodAccessException".不能打电话GetFullPath().任何人都可以让我知道我错过了什么?我该怎么做才能避免它?
我有一个 453MB XML 文件,我正在尝试使用SharpZipLib将其压缩为 ZIP 。
下面是我用来创建 zip 的代码,但它导致了OutOfMemoryException. 此代码成功压缩了 428MB 的文件。
知道为什么会发生异常,因为我不明白为什么,因为我的系统有足够的可用内存。
public void CompressFiles(List<string> pathnames, string zipPathname)
{
try
{
using (FileStream stream = new FileStream(zipPathname, FileMode.Create, FileAccess.Write, FileShare.None))
{
using (ZipOutputStream stream2 = new ZipOutputStream(stream))
{
foreach (string str in pathnames)
{
FileStream stream3 = new FileStream(str, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] buffer = new byte[stream3.Length];
try
{
if (stream3.Read(buffer, 0, buffer.Length) != buffer.Length)
{
throw new Exception(string.Format("Error reading '{0}'.", str));
}
}
finally
{ …Run Code Online (Sandbox Code Playgroud) 我使用以下代码创建一个zip文件:
var files = Directory.GetFiles(targetPath);
var zip = ZipFile.Create(targetPath + "/myzip.zip");
zip.BeginUpdate();
foreach (var file in files) zip.Add(file, CompressionMethod.Deflated);
zip.CommitUpdate();
zip.Close();
Run Code Online (Sandbox Code Playgroud)
我得到以下存档结构:
myzip.zip
- Folder1
- Folder2
- File1.txt
- File2.txt
- File3.txt
Run Code Online (Sandbox Code Playgroud)
但是我需要:
myzip.zip
- File1.txt
- File2.txt
- File3.txt
Run Code Online (Sandbox Code Playgroud)
请帮忙.
我正在尝试使用内存字符串中的文件创建 ZIP 并保存它。到目前为止,这是我的代码:
var zip = ZipFile.Create(Path.Combine(outputPath, fileName));
zip.BeginUpdate();
var fileStream = new MemoryStream(Encoding.Default.GetBytes(myStringVariable));
var outputMemStream = new MemoryStream();
var zipStream = new ZipOutputStream(outputMemStream);
var zipEntry = new ZipEntry("file.html");
zipEntry.DateTime = DateTime.Now;
zipStream.PutNextEntry(zipEntry);
StreamUtils.Copy(fileStream, zipStream, new byte[4096]);
zipStream.CloseEntry();
zip.Add(zipEntry);
zip.CommitUpdate();
zip.Close();
Run Code Online (Sandbox Code Playgroud)
然而它在 zip.Add(zipEntry); 上中断了。并抛出异常:
ZipException - 条目不能有任何数据
不知何故,我无法弄清楚出了什么问题。
我在 Azure 中有一个进程,可以生成大量 pdf 报告文件并将它们存储在 blob 存储中。我不是单独发送所有这些内容的链接,而是生成一个 zip 文件并将此链接发送给用户。
这个过程全部在一个进程中完成,并且一直运行良好。最近,我在将文件添加到 zip 存档时遇到了 OutOfMemory 异常错误,并且我正在努力寻找解决方案。
下面是我用来创建 zip 文件的代码(注意:使用 SharpLibZip 库)。目前,在添加大约 45 个每个文件 (PDF) 大约 3.5Mb 的文件后,它会失败并出现 OutOfMemoryException。当我点击以下行时发生故障:zipStream.PutNextEntry(newEntry)。
有谁知道我如何改进这个过程?压缩文件太小似乎会在这个级别失败。
Using outputMemStream As New MemoryStream()
Using zipStream As New ICSharpCode.SharpZipLib.Zip.ZipOutputStream(outputMemStream)
zipStream.SetLevel(7)
Dim collD3 As UserSurveyReportCollection = GetFileList(RequestID)
For Each entityD2 As UserSurveyReport In collD3
Try
Dim strF As String = entityD2.FileLocation
'Download blob as memorystream and add this stream to the zip file
Dim msR As New MemoryStream
msR = objA.DownloadBlobAsMemoryStream(azureAccount, ReportFolder, entityD2.FileName) …Run Code Online (Sandbox Code Playgroud) .zip 文件没有问题,但只有 7z。
FileStream fs = File.OpenRead(archiveFilenameIn);
zf = new ZipFile(fs); // This is where we encountered an error
Run Code Online (Sandbox Code Playgroud)