本文整理汇总了C#中Ionic.Zlib.ZlibStream.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# ZlibStream.Flush方法的具体用法?C# ZlibStream.Flush怎么用?C# ZlibStream.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zlib.ZlibStream
的用法示例。
在下文中一共展示了ZlibStream.Flush方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Comp
public static byte[] Comp(byte[] input)
{
using (var sourceStream = new MemoryStream(input))
{
using (var compressed = new MemoryStream())
{
using (var zipSteam = new ZlibStream(compressed, CompressionMode.Compress, CompressionLevel.Level9, true))
{
zipSteam.FlushMode = FlushType.Full;
//var buffer = new byte[1024];
//int len = sourceStream.Read(buffer, 0, buffer.Length);
//while (len > 0)
//{
// zipSteam.Write(buffer, 0, len);
// len = sourceStream.Read(buffer, 0, buffer.Length);
//}
sourceStream.CopyTo(zipSteam);
zipSteam.Flush();
return compressed.ToArray();
}
}
}
}
示例2: Compress
/// <summary>
/// Compress to CompressedData
/// </summary>
public static MemoryStream Compress(byte[] buffer)
{
var output = new MemoryStream();
using (ZlibStream zout = new ZlibStream(output, CompressionMode.Compress))
{
zout.Write(buffer, 0, buffer.Length);
zout.Flush();
}
return output;
}
示例3: CompressChunk
public byte[] CompressChunk()
{
//File and body headers ar emanaged outside
//All we do here is to write the compressed tag
using (MemoryStream ms = new MemoryStream())
{
using (ZlibStream compressed = new ZlibStream(ms, CompressionMode.Compress, true))
{
var w = new EndianBinaryWriter(EndianBitConverter.Big, compressed);
Tag.Write(w);
compressed.Flush();
}
return ms.ToArray();
}
}
示例4: ZibDecompress
public static byte[] ZibDecompress(byte[] data)
{
var ms = new MemoryStream(data);
using (var msDecompressed = new System.IO.MemoryStream())
{
using (var zs = new ZlibStream(msDecompressed, CompressionMode.Decompress, true))
{
int readByte = ms.ReadByte();
while (readByte != -1)
{
zs.WriteByte((byte)readByte);
readByte = ms.ReadByte();
}
zs.Flush();
}
return msDecompressed.ToArray();
}
}
示例5: Save
public void Save(Stream stream)
{
long dataStart = CalculateDataStartOffset();
stream.Seek(dataStart, SeekOrigin.Begin);
long fileStart = 0;
long compressedSize = 0;
long uncompressedSize = 0;
// Output file data
ZlibStream dataStream = null;
if (IsCompressed && IsCondensed)
{
dataStream = new ZlibStream(stream, CompressionMode.Compress, CompressionLevel.BestCompression, true);
dataStream.FlushMode = FlushType.Sync;
}
long compressedStart = 0;
for (int i = 0; i < Files.Count; i++)
{
IPackfileEntry entry = Files[i];
Stream fs = m_Streams[entry.Name];
bool isLast = (i == (Files.Count - 1));
PackfileEntry pfE = (PackfileEntry)entry;
var data = pfE.Data;
data.Start = (uint)fileStart;
data.Size = (uint)fs.Length;
data.Alignment = (IsCondensed) ? (ushort)16 : (ushort)1;
if (this.IsCompressed)
data.Flags = PackfileEntryFlags.Compressed;
if (IsCompressed && IsCondensed)
{
fs.CopyTo(dataStream);
dataStream.Flush();
long afterData = dataStream.TotalOut;
data.CompressedSize = (uint)(afterData - compressedStart);
compressedStart = afterData;
if (IsStr2)
{
fileStart += data.Size.Align(16);
uncompressedSize += data.Size.Align(16);
compressedSize += data.CompressedSize;
}
else
{
fileStart += data.Size; //.Align(16);
if (!isLast)
{
uncompressedSize += data.Size; //.Align(16);
//uint toSkip = data.Size.Align(16) - data.Size;
// for (int j = 0; j < toSkip; j++)
//dataStream.WriteByte(0);
}
else
{
uncompressedSize += data.Size;
}
compressedSize += data.CompressedSize;
}
}
else if (IsCondensed)
{
fs.CopyTo(stream);
data.CompressedSize = 0xFFFFFFFF;
fileStart += data.Size.Align(16);
if (isLast)
uncompressedSize += data.Size;
else
{
uint toSkip = data.Size.Align(16) - data.Size;
uncompressedSize += data.Size.Align(16);
stream.Seek(toSkip, SeekOrigin.Current);
}
}
else if (IsCompressed)
{
long beforeData = stream.Position;
using (dataStream = new ZlibStream(stream, CompressionMode.Compress, CompressionLevel.BestCompression, true))
{
dataStream.FlushMode = FlushType.Sync;
fs.CopyTo(dataStream);
dataStream.Flush();
}
long afterData = stream.Position;
data.CompressedSize = (uint)(afterData - beforeData);
fileStart += data.CompressedSize;
uncompressedSize += data.Size;
compressedSize += data.CompressedSize;
}
//.........这里部分代码省略.........
示例6: Compress
private byte[] Compress(byte[] revlogEntryData, int offset, int count)
{
using(var memoryStream = new MemoryStream())
{
using(var zlibStream = new ZlibStream(memoryStream, CompressionMode.Compress))
{
zlibStream.Write(revlogEntryData, offset, count);
zlibStream.Flush();
} // using
return memoryStream.ToArray();
} // using
}
示例7: writeToStreamOld
private void writeToStreamOld(Stream s, bool le, bool readOnly)
{
bool compress = true;
bool base64 = true;
using (var tw = new StreamWriter(s, System.Text.Encoding.ASCII))
{
tw.NewLine = "\n";
tw.WriteLine("Type: Floppy");
if (readOnly)
tw.WriteLine("Access: Read-Only");
else
tw.WriteLine("Access: Read-Write");
if (le)
tw.WriteLine("Byte-Order: Little-Endian");
else
tw.WriteLine("Byte-Order: Big-Endian");
int lb = 0, hb = 1;
if (!le)
{
lb = 1;
hb = 0;
}
byte[] bytes, cbytes;
bytes = new byte[1440 * 1024];
for (int i = 0; i < _words.Length; ++i)
{
var j = 2 * i;
bytes[j + lb] = (byte)_words[i];
bytes[j + hb] = (byte)(_words[i] >> 8);
}
if (compress)
{
tw.WriteLine("Compression: Zlib");
using (var ms = new MemoryStream())
{
using (var cmpr = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression, leaveOpen: true))
{
cmpr.Write(bytes, 0, bytes.Length);
cmpr.Flush();
}
cbytes = ms.ToArray();
}
}
else
{
tw.WriteLine("Compression: None");
cbytes = bytes;
}
if (base64)
{
var encoded = Convert.ToBase64String(cbytes, Base64FormattingOptions.InsertLineBreaks);
tw.WriteLine("Encoding: Base64");
tw.WriteLine("Content-Length: {0}", encoded.Length);
tw.WriteLine();
tw.WriteLine(encoded);
}
else
{
tw.WriteLine("Encoding: None");
tw.WriteLine("Content-Length: {0}", cbytes.Length);
tw.WriteLine();
tw.Flush();
tw.BaseStream.Write(bytes, 0, cbytes.Length);
}
}
}