本文整理汇总了C#中DeflateStream.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream.CopyTo方法的具体用法?C# DeflateStream.CopyTo怎么用?C# DeflateStream.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeflateStream
的用法示例。
在下文中一共展示了DeflateStream.CopyTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecompressProfile
static void DecompressProfile(string srcfile, string dstfile)
{
try
{
Console.WriteLine("Reading source...");
byte[] x = File.ReadAllBytes(srcfile); // load all bytes
byte[] y = new byte[x.Length-0x1A];
Console.WriteLine("Copying array...");
Array.Copy(x, 0x1A, y, 0, y.Length); // skip hash (0x14) + uncompresed size (0x4) + zlib compression type (0x2) = 0x1A
Console.WriteLine("Initializing streams...");
DeflateStream defStream = new DeflateStream(new MemoryStream(y),CompressionMode.Decompress);
FileStream fs = File.Create(dstfile);
Console.WriteLine("Decompressing data to destination...");
defStream.CopyTo(fs);
Console.WriteLine("Decompression done.\n" + dstfile);
defStream.Close();
fs.Close();
}
catch(Exception ex)
{
Console.WriteLine(ex.GetType().Name + " | " + ex.Message);
Console.Beep();
}
return;
}
示例2: Decompress
public static void Decompress(FileInfo fi)
{
// Get the stream of the source file.
using (FileStream inFile = fi.OpenRead())
{
// Get original file extension,
// for example "doc" from report.doc.cmp.
string curFile = fi.FullName;
string origName = curFile.Remove(curFile.Length
- fi.Extension.Length);
//Create the decompressed file.
using (FileStream outFile = File.Create(origName))
{
using (DeflateStream Decompress = new DeflateStream(inFile,
CompressionMode.Decompress))
{
// Copy the decompression stream
// into the output file.
Decompress.CopyTo(outFile);
Console.WriteLine("Decompressed: {0}", fi.Name);
}
}
}
}
示例3: ProcessChunk
//.........这里部分代码省略.........
var keyword = reader.GetNullTerminatedStringValue(maxLengthBytes: 79).ToString(defaultEncoding);
var bytesLeft = bytes.Length - keyword.Length - 1;
var value = reader.GetNullTerminatedStringValue(bytesLeft, defaultEncoding);
var textPairs = new List<KeyValuePair> { new KeyValuePair(keyword, value) };
var directory = new PngDirectory(PngChunkType.iTXt);
directory.Set(PngDirectory.TagTextualData, textPairs);
yield return directory;
}
else if (chunkType == PngChunkType.iTXt)
{
var reader = new SequentialByteArrayReader(bytes);
var keyword = reader.GetNullTerminatedStringValue(maxLengthBytes: 79).ToString(defaultEncoding);
var compressionFlag = reader.GetSByte();
var compressionMethod = reader.GetSByte();
var languageTag = reader.GetNullTerminatedStringValue(bytes.Length, defaultEncoding);
var translatedKeyword = reader.GetNullTerminatedStringValue(bytes.Length, defaultEncoding);
var bytesLeft = bytes.Length - keyword.Length - 1 - 1 - 1 - languageTag.Bytes.Length - 1 - translatedKeyword.Bytes.Length - 1;
byte[] textBytes = null;
if (compressionFlag == 0)
{
textBytes = reader.GetNullTerminatedBytes(bytesLeft);
}
else if (compressionFlag == 1)
{
if (compressionMethod == 0)
{
using (var inflaterStream = new DeflateStream(new MemoryStream(bytes, bytes.Length - bytesLeft, bytesLeft), CompressionMode.Decompress))
using (var decompStream = new MemoryStream())
{
#if !NET35
inflaterStream.CopyTo(decompStream);
#else
byte[] buffer = new byte[256];
int count;
int totalBytes = 0;
while ((count = inflaterStream.Read(buffer, 0, 256)) > 0)
{
decompStream.Write(buffer, 0, count);
totalBytes += count;
}
#endif
textBytes = decompStream.ToArray();
}
}
else
{
var directory = new PngDirectory(PngChunkType.iTXt);
directory.AddError("Invalid compression method value");
yield return directory;
}
}
else
{
var directory = new PngDirectory(PngChunkType.iTXt);
directory.AddError("Invalid compression flag value");
yield return directory;
}
if (textBytes != null)
{
if (keyword == "XML:com.adobe.xmp")
{
// NOTE in testing images, the XMP has parsed successfully, but we are not extracting tags from it as necessary