本文整理汇总了C#中System.IO.Compression.GZipStream.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.Flush方法的具体用法?C# GZipStream.Flush怎么用?C# GZipStream.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.GZipStream
的用法示例。
在下文中一共展示了GZipStream.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Gzip
private static int Gzip(Stream stream, FileStream fs)
{
int length = 0;
using (var ms = new MemoryStream())
{
byte[] buffer = new byte[BufferSize];
int count;
using (var gzip = new GZipStream(ms, CompressionMode.Compress, true))
{
while ((count = fs.Read(buffer, 0, BufferSize)) > 0)
{
gzip.Write(buffer, 0, count);
}
gzip.Flush();
}
ms.Seek(0, SeekOrigin.Begin);
while ((count = ms.Read(buffer, 0, BufferSize)) > 0)
{
length += count;
stream.Write(buffer, 0, count);
}
stream.Flush();
}
return length;
}
示例2: WriteGzip
public static void WriteGzip(XmlDocument theDoc, Stream theStream)
{
var ms = new MemoryStream();
var xmlSettings = new XmlWriterSettings
{
Encoding = Encoding.UTF8,
ConformanceLevel = ConformanceLevel.Document,
Indent = false,
NewLineOnAttributes = false,
CheckCharacters = true,
IndentChars = string.Empty
};
XmlWriter tw = XmlWriter.Create(ms, xmlSettings);
theDoc.WriteTo(tw);
tw.Flush();
tw.Close();
byte[] buffer = ms.GetBuffer();
var compressedzipStream = new GZipStream(theStream, CompressionMode.Compress, true);
compressedzipStream.Write(buffer, 0, buffer.Length);
// Close the stream.
compressedzipStream.Flush();
compressedzipStream.Close();
// Force a flush
theStream.Flush();
}
示例3: ManagedBitmap
public ManagedBitmap(string fileName)
{
try
{
byte[] buffer = new byte[1024];
MemoryStream fd = new MemoryStream();
Stream fs = File.OpenRead(fileName);
using (Stream csStream = new GZipStream(fs, CompressionMode.Decompress))
{
int nRead;
while ((nRead = csStream.Read(buffer, 0, buffer.Length)) > 0)
{
fd.Write(buffer, 0, nRead);
}
csStream.Flush();
buffer = fd.ToArray();
}
Width = buffer[4] << 8 | buffer[5];
Height = buffer[6] << 8 | buffer[7];
_colors = new Color[Width * Height];
int start = 8;
for (int i = 0; i < _colors.Length; i++)
{
_colors[i] = Color.FromArgb(buffer[start], buffer[start + 1], buffer[start + 2], buffer[start + 3]);
start += 4;
}
}
catch
{
LoadedOk = false;
}
}
示例4: ProcessAction
public void ProcessAction(Object eventObject)
{
lock (blacklistLock)
{
if(blacklist.Contains(eventObject))
{
blacklist.Remove(eventObject);
return;
}
}
var memoryStream = new MemoryStream();
var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress);
var writer = new StreamWriter(gzipStream);
serializer.Serialize(writer, eventObject);
writer.Flush();
gzipStream.Flush();
memoryStream.Flush();
writer.Close();
gzipStream.Close();
memoryStream.Close();
var obj = new EventObject { MessageType = eventObject.GetType().AssemblyQualifiedName, MessageBody = memoryStream.ToArray(), SessionId = sessionId };
eventRepository.Save(obj);
}
示例5: GZCompress
public static byte[] GZCompress(byte[] source)
{
byte[] buffer;
if ((source == null) || (source.Length == 0))
{
throw new ArgumentNullException("source");
}
try
{
using (MemoryStream stream = new MemoryStream())
{
using (GZipStream stream2 = new GZipStream(stream, CompressionMode.Compress, true))
{
Console.WriteLine("Compression");
stream2.Write(source, 0, source.Length);
stream2.Flush();
stream2.Close();
Console.WriteLine("Original size: {0}, Compressed size: {1}", source.Length, stream.Length);
stream.Position = 0L;
buffer = stream.ToArray();
}
}
}
catch (Exception exception)
{
LoggingService.Error("GZip压缩时出错:", exception);
buffer = source;
}
return buffer;
}
示例6: Compression
private MemoryStream Compression(byte[] bytes)
{
MemoryStream ms = new MemoryStream();
GZipStream gzip = new GZipStream(ms, CompressionLevel.Optimal);
gzip.Write(bytes, 0, bytes.Length);
gzip.Flush();
gzip.Close();
return ms;
}
示例7: Zip
public static byte[] Zip(byte[] bytes)
{
using (var destination = new MemoryStream())
using (var gzip = new GZipStream(destination, CompressionLevel.Fastest, false))
{
gzip.Write(bytes, 0, bytes.Length);
gzip.Flush();
gzip.Close();
return destination.ToArray();
}
}
示例8: Compress
public static byte[] Compress(this byte[] data)
{
using (MemoryStream ms = new MemoryStream())
{
using (GZipStream zs = new GZipStream(ms, CompressionMode.Compress))
{
zs.Write(data, 0, data.Length);
zs.Flush();
}
return ms.ToArray();
}
}
示例9: Unzip
public static byte[] Unzip(byte[] bytes)
{
using (var source = new MemoryStream(bytes))
using (var destination = new MemoryStream())
using (var gzip = new GZipStream(source, CompressionMode.Decompress, false))
{
gzip.CopyTo(destination);
gzip.Flush();
gzip.Close();
return destination.ToArray();
}
}
示例10: Save
public static void Save(ArpeggioDefinition arpeggio, string fileName)
{
Stream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
GZipStream gzip = new GZipStream(fileStream, CompressionMode.Compress, true);
SerializationUtils.Serialize(arpeggio, gzip);
gzip.Flush();
gzip.Close();
fileStream.Close();
fileStream.Dispose();
}
示例11: GZipCompress
public static byte[] GZipCompress(byte[] source)
{
var memoryStream = new MemoryStream();
var stream = new GZipStream(memoryStream, CompressionMode.Compress);
stream.Write(source, 0, source.Length);
stream.Flush();
stream.Close();
//Console.WriteLine("GZip : {0}", memoryStream.ToArray().Length);
return memoryStream.ToArray();
}
示例12: Compress
public Stream Compress(string content)
{
var ms = new MemoryStream();
using (var zip = new GZipStream(ms, CompressionMode.Compress, true))
{
var buffer = Encoding.UTF8.GetBytes(content);
zip.Write(buffer, 0, buffer.Length);
zip.Flush();
}
ms.Position = 0;
return ms;
}
示例13: Depress
/// <summary>
/// 解压二进制流
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static byte[] Depress(byte[] data)
{
using (var memoryStream = new MemoryStream(data))
using (var outStream = new MemoryStream())
{
using (var compressionStream = new GZipStream(memoryStream, CompressionMode.Decompress))
{
compressionStream.CopyTo(outStream);
compressionStream.Flush();
}
return outStream.ToArray();
}
}
示例14: Compress
/// <summary>
/// 压缩二进制流
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static byte[] Compress(byte[] data)
{
using (var memoryStream = new MemoryStream())
{
using (var compressionStream = new GZipStream(memoryStream, CompressionMode.Compress))
{
compressionStream.Write(data, 0, data.Length);
compressionStream.Flush();
}
//必须先关了compressionStream后才能取得正确的压缩流
return memoryStream.ToArray();
}
}
示例15: StoredScript
public StoredScript(String data, LighteningDataType dataType)
{
DataType = dataType;
Uncompressed = Encoding.UTF8.GetBytes(data);
using (MemoryStream result = new MemoryStream())
{
using (GZipStream gzStream = new GZipStream(result, CompressionLevel.Optimal, true))
{
gzStream.Write(Uncompressed, 0, Uncompressed.Length);
gzStream.Flush();
}
Compressed = result.ToArray();
}
}