本文整理汇总了C#中ICSharpCode.SharpZipLib.GZip.GZipOutputStream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# GZipOutputStream.Write方法的具体用法?C# GZipOutputStream.Write怎么用?C# GZipOutputStream.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.GZip.GZipOutputStream
的用法示例。
在下文中一共展示了GZipOutputStream.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compress
/// <summary>
/// 压缩文件为gz文件
/// </summary>
/// <param name="sourcefilename">压缩的文件路径</param>
/// <param name="zipfilename">压缩后的gz文件路径</param>
/// <returns></returns>
public static bool Compress(string sourcefilename, string zipfilename)
{
bool blResult;//表示压缩是否成功的返回结果
//为源文件创建读取文件的流实例
FileStream srcFile = File.OpenRead(sourcefilename);
//为压缩文件创建写入文件的流实例
GZipOutputStream zipFile = new GZipOutputStream(File.Open(zipfilename, FileMode.Create));
try
{
byte[] FileData = new byte[srcFile.Length];//创建缓冲数据
srcFile.Read(FileData, 0, (int)srcFile.Length);//读取源文件
zipFile.Write(FileData, 0, FileData.Length);//写入压缩文件
blResult = true;
return blResult;
}
catch
{
blResult = false;
return blResult;
}
finally
{
srcFile.Close();//关闭源文件
zipFile.Close();//关闭压缩文件
}
}
示例2: CtorErrMsg
public static byte[] CtorErrMsg(string msg, NameValueCollection requestParam)
{
using (MemoryStream ms = new MemoryStream())
{
//包总长度
int len = 0;
long pos = 0;
//包总长度,占位
WriteValue(ms, len);
int actionid = Convert.ToInt32(requestParam["actionid"]);
//StatusCode
WriteValue(ms, 10001);
//msgid
WriteValue(ms, Convert.ToInt32(requestParam["msgid"]));
WriteValue(ms, msg);
WriteValue(ms, actionid);
WriteValue(ms, "st");
//playerdata
WriteValue(ms, 0);
//固定0
WriteValue(ms, 0);
ms.Seek(pos, SeekOrigin.Begin);
WriteValue(ms, (int)ms.Length);
using (var gms = new MemoryStream())
using (var gzs = new GZipOutputStream(gms))
{
gzs.Write(ms.GetBuffer(), 0, (int)ms.Length);
gzs.Flush();
gzs.Close();
return gms.ToArray();
}
}
}
示例3: Compress
/// <summary>
/// 지정된 데이타를 압축한다.
/// </summary>
/// <param name="input">압축할 Data</param>
/// <returns>압축된 Data</returns>
public override byte[] Compress(byte[] input) {
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.CompressStartMsg);
// check input data
if(input.IsZeroLength()) {
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.InvalidInputDataMsg);
return CompressorTool.EmptyBytes;
}
byte[] output;
using(var compressedStream = new MemoryStream(input.Length)) {
using(var gzs = new GZipOutputStream(compressedStream)) {
gzs.SetLevel(ZipLevel);
gzs.Write(input, 0, input.Length);
gzs.Finish();
}
output = compressedStream.ToArray();
}
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.CompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);
return output;
}
示例4: TestGZip
public void TestGZip()
{
MemoryStream ms = new MemoryStream();
GZipOutputStream outStream = new GZipOutputStream(ms);
byte[] buf = new byte[100000];
System.Random rnd = new Random();
rnd.NextBytes(buf);
outStream.Write(buf, 0, buf.Length);
outStream.Flush();
outStream.Finish();
ms.Seek(0, SeekOrigin.Begin);
GZipInputStream inStream = new GZipInputStream(ms);
byte[] buf2 = new byte[buf.Length];
int pos = 0;
while (true) {
int numRead = inStream.Read(buf2, pos, 4096);
if (numRead <= 0) {
break;
}
pos += numRead;
}
for (int i = 0; i < buf.Length; ++i) {
Assertion.AssertEquals(buf2[i], buf[i]);
}
}
示例5: TestGZip
public void TestGZip()
{
MemoryStream ms = new MemoryStream();
GZipOutputStream outStream = new GZipOutputStream(ms);
byte[] buf = new byte[100000];
System.Random rnd = new Random();
rnd.NextBytes(buf);
outStream.Write(buf, 0, buf.Length);
outStream.Flush();
outStream.Finish();
ms.Seek(0, SeekOrigin.Begin);
GZipInputStream inStream = new GZipInputStream(ms);
byte[] buf2 = new byte[buf.Length];
int currentIndex = 0;
int count = buf2.Length;
while (true) {
int numRead = inStream.Read(buf2, currentIndex, count);
if (numRead <= 0) {
break;
}
currentIndex += numRead;
count -= numRead;
}
Assert.AreEqual(0, count);
for (int i = 0; i < buf.Length; ++i) {
Assert.AreEqual(buf2[i], buf[i]);
}
}
示例6: GZip_Compress_Extract_Test
public void GZip_Compress_Extract_Test() {
var plainStream = PlainText.ToStream();
plainStream.Seek(0, SeekOrigin.Begin);
var plainData = Encoding.UTF8.GetBytes(PlainText);
byte[] compressedData;
byte[] extractedData;
// Compress
using(var compressedStream = new MemoryStream())
using(var gzs = new GZipOutputStream(compressedStream)) {
gzs.SetLevel(5);
gzs.Write(plainData, 0, plainData.Length);
gzs.Finish();
compressedData = compressedStream.ToArray();
}
Assert.IsNotNull(compressedData);
// Extract
using(var compressedStream = new MemoryStream(compressedData)) {
// compressedStream.Seek(0, SeekOrigin.Begin);
using(var gzs = new GZipInputStream(compressedStream))
using(var extractedStream = new MemoryStream()) {
StreamTool.CopyStreamToStream(gzs, extractedStream);
extractedData = extractedStream.ToArray();
}
}
Assert.IsNotNull(extractedData);
string extractedText = Encoding.UTF8.GetString(extractedData).TrimEnd('\0');
Assert.AreEqual(PlainText, extractedText);
}
示例7: compress_gzip
/// <summary>
/// Compresses byte array using gzip
/// Compressed data is returned as a byte array
/// </summary>
/// <param name="inBytes">The bytes to compress</param>
public static byte[] compress_gzip(byte[] inBytes)
{
MemoryStream ContentsGzippedStream = new MemoryStream(); //create the memory stream to hold the compressed file
Stream s = new GZipOutputStream(ContentsGzippedStream); //create the gzip filter
s.Write(inBytes, 0, inBytes.Length); //write the file contents to the filter
s.Flush(); //make sure everythings ready
s.Close(); //close and write the compressed data to the memory stream
return ContentsGzippedStream.ToArray();
}
示例8: CompressByte
/// <summary>
/// 压缩byte数组
/// </summary>
/// <param name="inBytes">需要压缩的byte数组</param>
/// <returns>压缩好的byte数组</returns>
public static byte[] CompressByte(byte[] inBytes)
{
MemoryStream outStream = new MemoryStream();
Stream zipStream = new GZipOutputStream(outStream);
zipStream.Write(inBytes, 0, inBytes.Length);
zipStream.Close();
byte[] outData = outStream.ToArray();
outStream.Close();
return outData;
}
示例9: CompressBytes
/// <summary>
/// 压缩字节数组
/// 返回:已压缩的字节数组
/// </summary>
/// <param name="bytData">待压缩的字节数组</param>
/// <returns></returns>
public static byte[] CompressBytes(byte[] data)
{
MemoryStream o = new MemoryStream();
Stream s = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(o);
s.Write(data, 0, data.Length);
s.Close();
o.Flush();
o.Close();
return o.ToArray();
}
示例10: returnZippedbyteArray
public static byte[] returnZippedbyteArray(string stringToZip)
{
MemoryStream memStream = new MemoryStream();
Stream compressedStream = new GZipOutputStream(memStream);
byte[] byteArrayToZip = Encoding.UTF8.GetBytes(stringToZip.ToCharArray());
compressedStream.Write(byteArrayToZip ,0,byteArrayToZip.Length);
compressedStream.Flush();
compressedStream.Close();
return memStream.ToArray();
}
示例11: zip
public byte[] zip(string input)
{
byte[] data = Encoding.UTF8.GetBytes (input);
using (MemoryStream memory = new MemoryStream()) {
using (GZipOutputStream gzip = new GZipOutputStream(memory)) {
gzip.Write (data, 0, data.Length);
}//using
return memory.ToArray ();
}//using
}
示例12: Compress
/// <summary>
/// 压缩字节数组
/// </summary>
/// <param name="inputBytes">Input bytes.</param>
public static byte[] Compress (byte[] inputBytes)
{
using (var outStream = new MemoryStream ())
{
using (var zipStream = new GZipOutputStream (outStream))
{
zipStream.Write (inputBytes, 0, inputBytes.Length);
zipStream.Close ();
}
return outStream.ToArray ();
}
}
示例13: Compress
public static byte[] Compress( byte[] bytesToCompress )
{
byte[] rebyte = null;
MemoryStream ms = new MemoryStream();
GZipOutputStream s = new GZipOutputStream(ms);
s.Write( bytesToCompress , 0 , bytesToCompress.Length );
s.Close();
rebyte = ms.ToArray();
ms.Close();
return rebyte;
}
示例14: Compression
/// <summary>
/// 压缩
/// </summary>
public static byte[] Compression(byte[] src)
{
if (IsGZip(src))
return src;
MemoryStream ms = new MemoryStream();
GZipOutputStream gos = new GZipOutputStream(ms);
gos.Write(src, 0, src.Length);
gos.Close();
// 由于从第五个字节开始的4个长度都是表示修改时间,因此可以强行设定
byte[] result = ms.ToArray();
result[4] = result[5] = result[6] = result[7] = 0x00;
return result;
}
示例15: Compress
private const int COMPRESS_LEVEL = 7;// 0-9, 9 being the highest compression
#endregion
#region ICompressionProvider Members
public byte[] Compress(byte[] data)
{
using (var outputStream = new MemoryStream())
{
using (var compressStream = new GZipOutputStream(outputStream))
{
compressStream.SetLevel(COMPRESS_LEVEL);
compressStream.Write(data, 0, data.Length);
compressStream.Finish();
compressStream.Close();
return outputStream.ToArray();
}
}
}