应际蕾新浪微博,莫囧网,杏坛门
public static class compressor {
public static byte[] compress(byte[] data)
{
using (memorystream output = new memorystream())
{
using (gzipstream gzip = new gzipstream(output, compressionmode.compress, true))
{
gzip.write(data, 0, data.length);
gzip.close();
return output.toarray();
}
}
}
public static byte[] decompress(byte[] data)
{
using (memorystream input = new memorystream())
{
input.write(data, 0, data.length);
input.position = 0;
using (gzipstream gzip = new gzipstream(input, compressionmode.decompress, true))
{
using (memorystream output = new memorystream())
{
byte[] buff = new byte[64];
int read = -1;
read = gzip.read(buff, 0, buff.length);
while (read > 0)
{
output.write(buff, 0, read);
read = gzip.read(buff, 0, buff.length);
}
gzip.close();
return output.toarray();
}
}
}
}
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
网友评论