新聞中心
這篇文章主要介紹“.net如何實(shí)現(xiàn)壓縮功能”,在日常操作中,相信很多人在.net如何實(shí)現(xiàn)壓縮功能問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”.net如何實(shí)現(xiàn)壓縮功能”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
復(fù)制代碼 代碼如下:
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();
}
}
}
}
到此,關(guān)于“.net如何實(shí)現(xiàn)壓縮功能”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
標(biāo)題名稱:.net如何實(shí)現(xiàn)壓縮功能-創(chuàng)新互聯(lián)
文章出自:http://fisionsoft.com.cn/article/dgisdp.html