GZipStream压缩解压字符串
2009-08-24 07:17
399 查看
///
使用GZipStream压缩数据
public
byte
[] CompressionData(
byte
[] input)
{
byte
[] temp
=
null
;
try
{
using
(MemoryStream ms
=
new
MemoryStream())
{
using
(GZipStream compressStream
=
new
GZipStream(ms, CompressionMode.Compress,
true
))
{
//
写入目标流
compressStream.Write(input,
0
, input.Length);
}
temp
=
ms.ToArray();
}
}
catch
(Exception ex)
{
throw
ex;
}
return
temp;
}
///
解压缩数据
public
byte
[] DecompressionData(
byte
[] input)
{
byte
[] temp
=
null
;
try
{
using
(MemoryStream baseData
=
new
MemoryStream())
{
MemoryStream rmstemp
=
new
MemoryStream(input);
using
(GZipStream DecompressString
=
new
GZipStream(rmstemp, CompressionMode.Decompress))
{
byte
[] buff
=
new
byte
[
4096
];
int
n;
while
((n
=
DecompressString.Read(buff,
0
, buff.Length))
!=
0
)
{
baseData.Write(buff,
0
, n);
}
}
rmstemp.Dispose();
rmstemp.Close();
temp
=
baseData.ToArray();
}
}
catch
(Exception ex)
{
temp
=
null
;
}
return
temp;
}
使用GZipStream压缩数据
public
byte
[] CompressionData(
byte
[] input)
{
byte
[] temp
=
null
;
try
{
using
(MemoryStream ms
=
new
MemoryStream())
{
using
(GZipStream compressStream
=
new
GZipStream(ms, CompressionMode.Compress,
true
))
{
//
写入目标流
compressStream.Write(input,
0
, input.Length);
}
temp
=
ms.ToArray();
}
}
catch
(Exception ex)
{
throw
ex;
}
return
temp;
}
///
解压缩数据
public
byte
[] DecompressionData(
byte
[] input)
{
byte
[] temp
=
null
;
try
{
using
(MemoryStream baseData
=
new
MemoryStream())
{
MemoryStream rmstemp
=
new
MemoryStream(input);
using
(GZipStream DecompressString
=
new
GZipStream(rmstemp, CompressionMode.Decompress))
{
byte
[] buff
=
new
byte
[
4096
];
int
n;
while
((n
=
DecompressString.Read(buff,
0
, buff.Length))
!=
0
)
{
baseData.Write(buff,
0
, n);
}
}
rmstemp.Dispose();
rmstemp.Close();
temp
=
baseData.ToArray();
}
}
catch
(Exception ex)
{
temp
=
null
;
}
return
temp;
}
相关文章推荐
- C#使用GZipStream压缩与解压字符串
- GZip对字符串压缩和解压
- gzip解压压缩的字符串数据
- C# GZip对字符串压缩和解压
- C# GZipStream 压缩和解压文件
- GZipstream压缩解压文件夹方法2
- gzip解压压缩的字符串数据
- C# GZip对字符串压缩和解压
- 在C#中用GZipStream压缩与解压数据
- C# GZipStream 压缩 解压
- GzipStream的简单使用压缩和解压
- GzipStream 实现文本文件的(压缩--解压)
- GZipStream 压缩与解压数据
- C# GZip对字符串压缩和解压
- 使用.Net自带的GZipStream进行流压缩与解压
- java 读取 C存放到Memcached中的网页GZIP压缩字符串、并解压出网页文本
- GZip对字符串压缩和解压
- GzipStream压缩解压示例
- C# GZipStream 压缩 解压
- C# GZip对字符串压缩和解压