Gzip压缩:
var data = new byte[]
{
10, 26, 8, 236, 2, 18, 21, 10, 1, 49, 16, 2, 24, 153, 208, 255, 255, 255, 255, 255, 255, 255, 1, 24, 0, 24, 141, 10,
10, 26, 8, 237, 2, 18, 21, 10, 1, 49, 16, 2, 24, 153, 208, 255, 255, 255, 255, 255, 255, 255, 1, 24, 0, 24, 141, 10
};
var ms = new MemoryStream();
var stream = new GZipOutputStream(ms);
try {
stream.Write(data, 0, data.Length);
}
finally {
stream.Close();
ms.Close();
}
Gzip解压缩:
var data = new byte[]
{
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 226, 82, 226, 248, 193, 40, 36, 203, 197, 104, 40, 192, 36, 177, 224, 239, 127,
8, 96, 148, 96, 144, 248, 242, 5, 198, 225, 82, 226, 248, 9, 87, 179, 8, 187, 26, 64, 0, 0, 0, 255, 255, 54, 169,
169, 80, 72, 0, 0, 0
};
var dataBuffer = new byte[4096];
var t = new byte[0];
using (var ms = new MemoryStream(data)) {
using (var gzipStream = new GZipInputStream(ms)) {
using (var outMs = new MemoryStream()) {
StreamUtils.Copy(gzipStream, outMs, dataBuffer);
}
}
}