使用 C# 计算 Zip 文件中的文件数量
我正在生成一些 .csv 文件,并且需要将其压缩到 Zip 文件中。好吧,我有一个框架可以做到这一点,也许一切都会好起来的。
但!正如 TDD 所说,在进行一些测试之后,我就可以编写代码了!
我的第一个测试听起来很简单,但我在读取 Zip 文件时遇到一些问题,有人知道计算 zip 文件中文件数量的简单方法吗?
I'm generating some .csv files and I need to compress this inside a Zip File. Ok, I have a framework to do this and probably everything will be fine.
But! As TDD says I just can write code, after I have some tests!
My first test sound simple, but I'm having some problems reading the Zip file, anyone know a simple way to count the number of files in my zip file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您似乎正在寻找类似 DotNetZip 的内容。
You seem to be looking for something like DotNetZip.
我不认为你问的是 TDD 问题,但无论如何我都会回答。
现在,使用您选择的库,让
FileCounter
工作。一旦它工作并且通过了测试,如果您愿意,请重构代码,以便它使用模拟框架来模拟对 zip 库的调用。现在您不再依赖文件系统。 (我可能不会走这么远,除非你的测试因磁盘 I/O 减慢太多)I don't think that was a TDD question you asked but I'll answer it anyway.
Now, using the library of your choice, make
FileCounter
work. Once it works and you have a passing test, if you so choose, refactor the code so that it uses a mocking framework to mock out the calls to the zip library. Now you don't have a dependency on the file system. (I probably wouldn't go this far unless your tests are slowed down too much by the disk I/O)或者使用 SharpZipLib 和 请参阅此示例
Or use SharpZipLib and see this for some examples