带有 crc 变量详细信息的 ICSharpCode.SharpZipLib.Zip 示例
我正在使用 icsharpziplib dll 在 asp.net 中使用 c# 来压缩共享点文件
当我打开 output.zip 文件时,它显示“zip 文件已损坏或损坏”。 Output.zip 中文件的 crc 值显示为 000000。
- 我们如何使用 icsharpziplib dll 计算或配置 crc 值?
- 任何人都可以提供一个很好的示例如何使用内存流进行压缩吗?
I am using icsharpziplib dll for zipping sharepoint files using c# in asp.net
When i open the output.zip file, it is showing "zip file is either corrupted or damaged".
And the crc value for files in the output.zip is showing as 000000.
- How do we calculate or configure crc value using icsharpziplib dll?
- Can any one have the good example how to do zipping using memorystreams?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您没有创建每个 ZipEntry。
这是我根据我的需要进行调整的代码:
http://wiki.sharpdevelop.net/SharpZipLib-Zip-Samples.ashx#Create_a_Zip_fromto_a_memory_stream_or_byte_array_1
无论如何,使用 SharpZipLib,您可以通过多种方式处理 zip 文件:
ZipFile
类、ZipOutputStream
和FastZip
。我使用 ZipOutputStream 创建内存中 ZIP 文件,向其中添加内存流,最后刷新到磁盘,效果非常好。为什么选择 ZipOutputStream?因为如果您想指定压缩级别并使用
Streams
,这是唯一可用的选择。祝你好运 :)
it seems you're not creating each ZipEntry.
Here's is a code that I adapted to my needs:
http://wiki.sharpdevelop.net/SharpZipLib-Zip-Samples.ashx#Create_a_Zip_fromto_a_memory_stream_or_byte_array_1
Anyway with SharpZipLib there are many ways you can work with zip file: the
ZipFile
class, theZipOutputStream
and theFastZip
.I'm using the ZipOutputStream to create an in-memory ZIP file, adding in-memory streams to it and finally flushing to disk, and it's working quite good. Why ZipOutputStream? Because it's the only choice available if you want to specify a compression level and use
Streams
.Good luck :)
1:
您可以手动完成,但 ICSharpCode 库会为您处理。我还发现:“zip 文件已损坏或损坏”也可能是由于未正确添加 zip 条目名称(例如位于子文件夹链中的条目)造成的。
2:
我通过创建压缩助手实用程序解决了这个问题。我必须动态地编写并返回 zip 文件。临时文件不是一个选项,因为该进程将由 Web 服务运行。
这样做的技巧是 BeginZip()、AddEntry() 和 EndZip() 方法(因为我将其制作成要调用的实用程序。如果需要,您可以直接使用代码)。
我从示例中排除的内容是初始化检查(例如首先错误地调用 EndZip())和正确的处理代码(最好实现 IDisposable 并关闭您的 zipfileStream 和内存流(如果适用))。
因此,您实际上是将 zipOutputStream 写入内存流。然后一旦 _zipOutputStream 关闭,就可以返回内存流的内容。
只需要注意您想要向 zip 文件添加多少内容(进程延迟/IO/超时等)。
1:
You could do it manually but the ICSharpCode library will take care of it for you. Also something I've discovered: 'zip file is either corrupted or damaged' can also be a result of not adding your zip entry name correctly (such as an entry that sits in a chain of subfolders).
2:
I solved this problem by creating a compressionHelper utility. I had to dynamically compose and return zip files. Temp files were not an option as the process was to be run by a webservice.
The trick with this was a BeginZip(), AddEntry() and EndZip() methods (because I made it into a utility to be invoked. You could just use the code directly if need be).
Something I've excluded from the example are checks for initialization (like calling EndZip() first by mistake) and proper disposal code (best to implement IDisposable and close your zipfileStream and your memoryStream if applicable).
So you're actually having the zipOutputStream write to a memoryStream. Then once _zipOutputStream is closed, you can return the contents of the memoryStream.
Just be aware of how much you want to add to a zipfile (delay in process/IO/timeouts etc).