适用于 Windows Mobile 的 gzip 工具比 SharpZipLib 更好?
我在用 c# 编写的 Windows Mobile 应用程序上使用 SharpZipLib 进行 gzip
我有这个代码
public static bool gzDecompressFile(String inputFilePath, String outputFilePath)
{
if (!File.Exists(inputFilePath))
return false;
if (File.Exists(outputFilePath))
File.Delete(outputFilePath);
FileStream fs = File.OpenRead(inputFilePath);
FileStream fsOut = File.OpenWrite(outputFilePath);
GZipInputStream gzipIn = new GZipInputStream(fs);
// Compress file in 1kb chunks
byte[] chunk = new byte[1024];
int read = 1;
while (read > 0)
{
read = gzipIn.Read(chunk, 0, chunk.Length);
if (read > 0)
{
fsOut.Write(chunk, 0, read);
}
}
fsOut.Close();
fs.Close();
return true;
}
For a 1.6MB --> 7MB解压需要4-5分钟。
您知道更好的紧凑框架吗?
I use SharpZipLib for gzip on a Windows Mobile application written in c#
I have this code
public static bool gzDecompressFile(String inputFilePath, String outputFilePath)
{
if (!File.Exists(inputFilePath))
return false;
if (File.Exists(outputFilePath))
File.Delete(outputFilePath);
FileStream fs = File.OpenRead(inputFilePath);
FileStream fsOut = File.OpenWrite(outputFilePath);
GZipInputStream gzipIn = new GZipInputStream(fs);
// Compress file in 1kb chunks
byte[] chunk = new byte[1024];
int read = 1;
while (read > 0)
{
read = gzipIn.Read(chunk, 0, chunk.Length);
if (read > 0)
{
fsOut.Write(chunk, 0, read);
}
}
fsOut.Close();
fs.Close();
return true;
}
For a 1.6MB --> 7MB decompression it takes 4-5 minutes.
Do you know a better one for Compact Framework?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 1.6MB 解压缩到 7MB 需要 4 分钟多的时间,速度非常慢。
我想到的一些事项:
我们最初使用 SharpLibZip,但后来改用商业 Xceed ZIP.NET 库以利用批处理功能(以及对 .NET 和 .NET Compact Framework 的支持)。 Xceed 库还支持 GZip。即使在我们老式的 400 MHz Windows CE 4.2 设备上,我们也只需要大约 20-30 秒即可解压 6 MB 文件(尽管是使用 XCeed ZIP.NET 的 ZIP 格式)。
另外,如果我没记错的话,我相信 .NET Compact Framework 支持 GZip。另外,将 FileStream 放置在 using 语句中,以确保在方法中间发生异常时关闭它们。
Decompressing 1.6MB to 7MB in over 4 minutes is dreadfully slow.
Some items that come to mind:
We originally started with SharpLibZip but switched to the commercial Xceed ZIP.NET library to take advantage of the batching capabilities (and the support for both .NET and .NET Compact Frameworks). The Xceed library also supports GZip. Even on our archaic 400 MHz Windows CE 4.2 devices it takes us only about 20-30 seconds to decompress a 6 MB file (albeit in a ZIP using XCeed ZIP.NET).
Also, if I'm not mistaken, I believe .NET Compact Framework has support for GZip. On a side note, place your FileStreams in using statements to ensure they are closed in the event an exception occurs in the middle of your method.
压缩非常消耗 CPU 资源。也许……这就是需要多长时间。
尝试 DotNetZip - 不确定是否更快,但它是免费的,易于尝试。
DotNetZip 中的 GZipStream 可以替代 .NET BCL 中的 GZipStream。
由于您正在执行 GZIP 而不是 ZIP,因此您只需要 Ionic.Zlib.dll ,而不是 Ionic.Zip.dll 。前者是后者的严格子集。
编辑:代码示例
(上述代码中的 GZipStream 由 Ionic.Zlib.dll 提供。)
Compression is very CPU intensive. It may be that ... that's just how long it takes.
Try DotNetZip - not sure if faster, but it is free, easy to try.
There's a GZipStream in DotNetZip that is a replacement for the GZipStream in the .NET BCL.
Since you are doing GZIP and not ZIP, You need only Ionic.Zlib.dll, not Ionic.Zip.dll . The former is a strict subset of the latter.
EDIT: code sample
(The GZipStream in the above code is provided by Ionic.Zlib.dll . )
我使用 ZIP 组件作为 Resco Mobile Toolkit 的一部分: http://www.resco .net/developer/mobileformstoolkit/overview.aspx
该工具包的价格可能令人望而却步 - 这取决于您是否需要任何其他控件。
I use the ZIP component as part of the Resco Mobile Toolkit: http://www.resco.net/developer/mobileformstoolkit/overview.aspx
The price of the toolkit is probably prohibitive - it depends if you have a need for any of the other controls.