我使用DotNetZip创建一个带有内存字符串的zip存档,并使用以下代码将其下载为附件.
byte[] formXml = UTF8Encoding.Default.GetBytes("<form><pkg>Test1</pkg></form>");
byte[] formHtml = UTF8Encoding.Default.GetBytes("<html><body>Test2</body></html>");
ZipFile zipFile = new ZipFile();
zipFile.AddEntry("Form.xml", formXml);
zipFile.AddEntry("Form.html", formHtml);
Response.ClearContent();
Response.ClearHeaders();
Response.AppendHeader("content-disposition", "attachment; filename=FormsPackage.zip");
zipFile.Save(Response.OutputStream);
zipFile.Dispose();
Run Code Online (Sandbox Code Playgroud)
现在我需要对SharpZipLib做同样的事情.我该怎么做 ?SharpZipLib是否支持将文件添加为字节数组?
我正在使用SharpZipLib来解压缩文件.我的代码一直很好地适用于所有zip文件,除了我正在提取的zip文件...
得到这个例外:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: length
Run Code Online (Sandbox Code Playgroud)
正在抛出异常 size = s.Read(data, 0, data.Length);
Hereb是我的代码......
public static void UnzipFile(string sourcePath, string targetDirectory)
{
try
{
using (ZipInputStream s = new ZipInputStream(File.OpenRead(sourcePath)))
{
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
//string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
if (targetDirectory.Length > 0)
{
Directory.CreateDirectory(targetDirectory);
}
if (fileName != String.Empty)
{
using (FileStream streamWriter = File.Create(targetDirectory + fileName))
{
int size = …Run Code Online (Sandbox Code Playgroud) 我正在Sharpziplib version 0.86提取一个zip文件。它工作正常,但是在通过代码提取Winzip文件时,Lastwritetime在几秒钟内发生了变化...
也用过这个 File.SetLastWriteTime(fullPath, theEntry.DateTime);
实际文件Lastwritetime:4/8/2010 2:29:03PM
使用Winzip 压缩该文件并使用代码解压缩该文件后,提取的文件Lastwritetime更改为4/8/2010 2:29:04PM...对此是否有任何解决办法???
我需要解压缩.Z文件列表,这些文件将使用Visual Basic.NET保存在一个文件夹中.例如,考虑有一个像这样的文件夹C:\FilesToBeUnzipped.在这个文件夹里面会有5到6个文件,扩展名为.Z.我需要解压缩所有这些.Z文件并将解压缩的文件保存在像这样的文件夹中C:\UnzippedDataFiles.
这在VB.NET中是否可行?是否有任何免费的组件或类库来实现它?
我正在尝试使用 SharpZipLib 生成 zip 文件并让客户端下载它。
当前 zip 文件夹已创建并可在客户端计算机上使用,但问题是 download.zip 文件夹为空。文件夹中指定的文件在 zip 文件夹中不可用。
下面是我尝试过的代码。
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
ICSharpCode.SharpZipLib.Checksums.Crc32 crc = new ICSharpCode.SharpZipLib.Checksums.Crc32();
//stream directly to client.
ICSharpCode.SharpZipLib.Zip.ZipOutputStream output = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(response.OutputStream);
output.SetLevel(9);
string[] files = Directory.GetFiles("D:/newfolder/");
for (int i = 0; i < files.Length; i++)
{
ICSharpCode.SharpZipLib.Zip.ZipEntry entry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(files[i].ToString());
entry.DateTime = DateTime.Now;
System.IO.FileStream fs = new System.IO.FileStream(files[i].ToString(), FileMode.Open);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
output.PutNextEntry(entry);
output.Write(buffer, 0, …Run Code Online (Sandbox Code Playgroud) 我有一个文件传输应用程序,可以发送文件和文件夹.(服务器 - 客户端)
我试图通过TCP(套接字)发送数据,我已经为传输数据的方式做了一些规则,所以如果它发送一个包含许多文件的大文件夹,它应该将它们压缩成一个zip文件首先然后当该zip文件发送时,接收器必须解压缩它.所以我决定使用SharpZibLib,我对此有疑问.

PS:
首先是时间优先,使用SharpZipLib的目的是将(太多文件)放在一个文件中,这样发送的速度比发送(太多文件)的速度快一个.
这里有更多细节.
我正在从C#(使用SharpZipLib)发送一个gzip压缩字符串到PHP,我用readgzfile解压缩.这是有效的,但是字符串中的每个字符后跟两个奇怪的字符(在控制台中使用vim显示为^@).我也试过gzopen/gzread但结果相同.
当我用字符串$clean= preg_replace('/[^(\x20-\x7F)]*/','', $string);清除字符串中的非ASCII字符时,$ clean字符串与C#中的字符串相同.
虽然这有效,但我想知道发生了什么以及为什么这样我可以确保它始终有效或提出更好的解决方案.
我在尝试使用SharpZipLib库中的.bz2内容时遇到了麻烦,我无法在其他地方找到任何帮助.
任何帮助或建议将不胜感激,如果有人能指出我现有的解决方案,我可以从中学到这将是太棒了!
以下是我正在尝试做的事情,但显然它不起作用.目前我遇到的问题是在标记的行上未处理'EndOfStreamException'.代码有点混乱,我从来没有尝试过这样的事情......
正如你可以告诉我在解压缩之前从网上下载这个,我很确定部分代码可以正常工作.
while ((inputByte = responseStream.ReadByte()) != -1)
{
using (MemoryStream ms = new MemoryStream())
{
using (BinaryWriter writer = new BinaryWriter(ms))
{
writer.Write((byte)inputByte);
}
using (BZip2InputStream unzip = new BZip2InputStream(ms)) //Exception occurs here
{
buffer = new byte[unzip.Length];
unzip.Read(buffer, 0, buffer.Length);
}
using (FileStream fs = new FileStream(fPath, FileMode.OpenOrCreate, FileAccess.Write))
{
fs.Write(buffer, 0, buffer.Length);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我的代码中有以下方法:
private bool GenerateZipFile(List<FileInfo> filesToArchive, DateTime archiveDate)
{
try
{
using (ZipOutputStream zipStream = new ZipOutputStream(File.Create(GetZipFileName(archiveDate))))
{
zipStream.SetLevel(9); // maximum compression.
byte[] buffer = new byte[4096];
foreach (FileInfo fi in filesToArchive)
{
string fileName = ZipEntry.CleanName(fi.Name);
ZipEntry entry = new ZipEntry(fileName);
entry.DateTime = fi.LastWriteTime;
zipStream.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(fi.FullName))
{
StreamUtils.Copy(fs, zipStream, buffer);
}
zipStream.CloseEntry();
}
zipStream.Finish();
zipStream.Close();
}
return true;
}
catch (Exception ex)
{
OutputMessage(ex.ToString());
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
此代码生成包含所有正确条目的ZIP文件,但每个文件都列为4 TB(解压缩和打包),并在尝试打开时创建以下错误:
Extracting to "C:\winnt\profiles\jbladt\LOCALS~1\Temp\"
Use Path: no …Run Code Online (Sandbox Code Playgroud) 如何使用没有压缩的SharpZipLib将文件添加到Zip存档?
谷歌上的例子看起来很糟糕.