本文整理汇总了C#中ICSharpCode.SharpZipLib.GZip.GZipOutputStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# GZipOutputStream.Close方法的具体用法?C# GZipOutputStream.Close怎么用?C# GZipOutputStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.GZip.GZipOutputStream
的用法示例。
在下文中一共展示了GZipOutputStream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoubleClose
public void DoubleClose()
{
var memStream = new TrackedMemoryStream();
var s = new GZipOutputStream(memStream);
s.Finish();
s.Close();
s.Close();
memStream = new TrackedMemoryStream();
using (GZipOutputStream no2 = new GZipOutputStream(memStream)) {
s.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_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();
}
示例4: 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;
}
示例5: 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();
}
示例6: 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();
}
示例7: 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 ();
}
}
示例8: 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;
}
示例9: 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;
}
示例10: 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();
}
}
}
示例11: GZip
public byte[] GZip(string text)
{
var buffer = Encoding.UTF8.GetBytes(text);
using (var ms = new MemoryStream())
using (var zipStream = new GZipOutputStream(ms))
{
zipStream.Write(buffer, 0, buffer.Length);
zipStream.Close();
var compressed = ms.ToArray();
var gzBuffer = new byte[compressed.Length + 4];
Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);
return gzBuffer;
}
}
示例12: AddToStream
override public void AddToStream (Stream stream, EventTracker tracker)
{
if (ChildCount > 1)
throw new Exception ("Gzip file " + Uri + " has " + ChildCount + " children");
if (tracker != null)
tracker.ExpectingAdded (UriFu.UriToEscapedString (this.Uri));
UnclosableStream unclosable;
unclosable = new UnclosableStream (stream);
GZipOutputStream gz_out;
gz_out = new GZipOutputStream (unclosable);
MemoryStream memory;
memory = new MemoryStream ();
// There should just be one child
foreach (FileObject file in Children)
file.AddToStream (memory, tracker);
gz_out.Write (memory.ToArray (), 0, (int) memory.Length);
memory.Close ();
gz_out.Close ();
}
示例13: Compress
/* KMP message data format
* Uncompressed data: [bool-false : data]
* Compressed data: [bool-true : Int32-uncompressed length : compressed_data]
*/
public static byte[] Compress(byte[] data, bool forceUncompressed = false)
{
if (data == null) return null;
byte[] compressedData = null;
MemoryStream ms = null;
GZipOutputStream gzip = null;
try
{
ms = new MemoryStream();
if (data.Length < MESSAGE_COMPRESSION_THRESHOLD || forceUncompressed)
{
//Small message, don't compress
using (BinaryWriter writer = new BinaryWriter(ms))
{
writer.Write(false);
writer.Write(data, 0, data.Length);
compressedData = ms.ToArray();
ms.Close();
writer.Close();
}
}
else
{
//Compression enabled
Int32 size = data.Length;
using (BinaryWriter writer = new BinaryWriter(ms))
{
writer.Write(true);
writer.Write(size);
gzip = new GZipOutputStream(ms);
gzip.Write(data, 0, data.Length);
gzip.Close();
compressedData = ms.ToArray();
ms.Close();
writer.Close();
}
}
}
catch
{
return null;
}
finally
{
if (gzip != null) gzip.Dispose();
if (ms != null) ms.Dispose();
}
return compressedData;
}
示例14: Save
public static void Save(KPTranslation kpTrl, Stream sOut,
IXmlSerializerEx xs)
{
if(xs == null) throw new ArgumentNullException("xs");
#if !KeePassLibSD
GZipStream gz = new GZipStream(sOut, CompressionMode.Compress);
#else
GZipOutputStream gz = new GZipOutputStream(sOut);
#endif
XmlWriterSettings xws = new XmlWriterSettings();
xws.CheckCharacters = true;
xws.Encoding = StrUtil.Utf8;
xws.Indent = true;
xws.IndentChars = "\t";
XmlWriter xw = XmlWriter.Create(gz, xws);
xs.Serialize(xw, kpTrl);
xw.Close();
gz.Close();
sOut.Close();
}
示例15: SaveToFile
public static void SaveToFile(KPTranslation kpTrl, string strFileName)
{
FileStream fs = new FileStream(strFileName, FileMode.Create,
FileAccess.Write, FileShare.None);
#if !KeePassLibSD
GZipStream gz = new GZipStream(fs, CompressionMode.Compress);
#else
GZipOutputStream gz = new GZipOutputStream(fs);
#endif
XmlWriterSettings xws = new XmlWriterSettings();
xws.CheckCharacters = true;
xws.Encoding = new UTF8Encoding(false);
xws.Indent = true;
xws.IndentChars = "\t";
XmlWriter xw = XmlWriter.Create(gz, xws);
XmlSerializer xmlSerial = new XmlSerializer(typeof(KPTranslation));
xmlSerial.Serialize(xw, kpTrl);
xw.Close();
gz.Close();
fs.Close();
}