本文整理汇总了C#中System.IO.Compression.DeflateStream.WriteByte方法的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream.WriteByte方法的具体用法?C# DeflateStream.WriteByte怎么用?C# DeflateStream.WriteByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.DeflateStream
的用法示例。
在下文中一共展示了DeflateStream.WriteByte方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
FileStream source = File.OpenRead(@"D:\test.txt");
FileStream destination = File.Create(@"D:\archive.dfl");
DeflateStream compressor = new DeflateStream(destination, CompressionMode.Compress);
int theByte = source.ReadByte();
while (theByte != -1)
{
compressor.WriteByte((byte)theByte);
theByte = source.ReadByte();
}
compressor.Close();
}
示例2: processChunk
static Patch processChunk(byte[] orig, byte[] mod, int chunkStart, int chunkEnd) {
int patchSize = chunkEnd - chunkStart;
Debug.Assert(patchSize < Patch.MaxPatchSize);
int matchAreaSize = Patch.MatchAreaSize(patchSize);
int matchBefore = (matchAreaSize - patchSize) / 2;
int matchAfter = matchAreaSize - (patchSize + matchBefore);
Debug.Assert(matchBefore <= chunkStart);
Debug.Assert(chunkEnd + matchAfter <= orig.Length);
byte[] origBytes = new byte[matchAreaSize];
byte[] patchBytes = new byte[patchSize];
Array.ConstrainedCopy(orig, chunkStart - matchBefore, origBytes, 0, matchAreaSize);
Array.ConstrainedCopy(mod, chunkStart, patchBytes, 0, patchSize);
MemoryStream ms = new MemoryStream();
DeflateStream comp = new DeflateStream(ms, CompressionMode.Compress);
comp.WriteByte(0);
comp.Flush();
long base_len = ms.Length;
comp.Write(origBytes, 0, origBytes.Length);
comp.Flush();
return new Patch(origBytes, patchBytes, matchBefore, Convert.ToInt32(ms.Length - base_len));
}
示例3: Main
static void Main(string[] args)
{
var filestream = File.Create("file.txt");
var writer = new StreamWriter(filestream);
writer.WriteLine("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
Console.WriteLine("Init string:\n\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"");
writer.Close();
filestream = File.Open("file.txt", FileMode.Open);
var memStream = new MemoryStream();
var copressWriter = new DeflateStream(memStream, CompressionMode.Compress);
int readbyte = filestream.ReadByte();
while (readbyte != -1)
{
copressWriter.WriteByte((byte)readbyte);
readbyte = filestream.ReadByte();
}
copressWriter.Close();
filestream.Close();
File.Delete("file.txt");
filestream = File.Open("file.txt", FileMode.Create);
filestream.Write(memStream.ToArray(), 0, memStream.ToArray().Length);
filestream.Close();
var reader = File.OpenText("file.txt");
string readStr = reader.ReadToEnd();
reader.Close();
Console.WriteLine("\nString after archivation:");
Console.WriteLine(readStr);
Console.ReadKey();
}
示例4: JunkAtTheEnd
public void JunkAtTheEnd ()
{
// Write a deflated stream, then some additional data...
using (MemoryStream ms = new MemoryStream())
{
// The compressed stream
using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Compress, true))
{
stream.WriteByte(1);
stream.Flush();
}
// Junk
ms.WriteByte(2);
ms.Position = 0;
// Reading: this should not hang
using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Decompress))
{
byte[] buffer = new byte[512];
int len = stream.Read(buffer, 0, buffer.Length);
Console.WriteLine(len == 1);
}
}
}