Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
如果您要压缩数据,那么您可能会考虑高密度序列化,而不是压缩。像protobuf之类的东西。 这里有一些 C# 实现。对于现有对象,protobuf-net 在我看来是最容易实现的(披露:我是作者 - 但它是免费的等)。您只需序列化到流,或者如果您想要一个
byte[]
,一个单独的MemoryStream
。对于通过套接字连续使用(而不是 HTTP 的谨慎请求/响应),我建议查看
Serializer.SerializeWithLengthPrefix
/Serializer.DeserializeWithLengthPrefix 操作(protobuf 本身不包含终止符,因此需要长度前缀来处理单独的消息)。
If you are compressing data, then you might look at high-density serialization, rather than compression. Something like protobuf. There are a few C# implementations here. For existing objects, protobuf-net is IMO the simplest to implement (disclosure: I'm the author - but it is free etc). You just serialize to the stream, or if you want a
byte[]
, a separateMemoryStream
.For continuous use over a socket (rather than the discreet request/response of HTTP), I would suggest looking at the
Serializer.SerializeWithLengthPrefix
/Serializer.DeserializeWithLengthPrefix
operations (protobuf doesn't itself include a terminator, so a length-prefix is necessary to handle separate messages).DotNetZip 提供本机支持并具有相当友好的 API,我认为比 SharpZipLib 更灵活:编辑:不幸的是,DotNetZip 有一些关键问题,该项目似乎不再得到积极维护。因此,实际上不建议在生产代码中使用该库。
更好的替代方案是使用 SharpZipLib(如果您遵守其基于 GPL 的许可证),它是 zlib 的 .NET 端口之一 或 .NET 4.5 的 zip 支持,如此答案中所示。
DotNetZip offers native support and has a quite friendly API and is my opinion more flexible than SharpZipLib:EDIT: Unfortunately, DotNetZip has some critical issues and the project seems no longer be actively be maintained. Therefore, this library can't really be recommended for use in production code.
Better alternatives would be to use SharpZipLib (if you comply with their GPL-based license), one of the .NET ports of zlib or the zip support of .NET 4.5 as shown in this answer.
SharpZipLib 是一种替代方案。据说比框架库GZipStream写得更周到
SharpZipLib is an alternative. It's said that it's written more thoughtfully than the framework library GZipStream
.NET 3+ 现在具有内置 Zip 支持,其中 ZipPackage 类。
.NET 3+ has built-in Zip support now, with the ZipPackage class.
LZMA 应该是最好的压缩方法之一。 7-Zip 是 LZMA 的公共域 SDK 实现,可在此处免费下载:
http://www.7-Zip. 7-zip.org/sdk.html
有关压缩算法的维基百科:
LZMA is supposed to be among the best for compression. 7-Zip is a public domain SDK implementation of LZMA, freely downloadable here:
http://www.7-zip.org/sdk.html
Wikipedia on compression algorithms: