当前位置: 首页>>代码示例>>C#>>正文


C# DeflateStream.CopyTo方法代码示例

本文整理汇总了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;
    }
开发者ID:Erik-JS,项目名称:Misc-Stuff,代码行数:29,代码来源:ProfileTool.cs

示例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);
                }
            }
        }
    }
开发者ID:SebsCodeVault,项目名称:DeflateStream,代码行数:26,代码来源:Program.cs

示例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
开发者ID:yjqGitHub,项目名称:metadata-extractor-dotnet,代码行数:67,代码来源:PngMetadataReader.cs


注:本文中的DeflateStream.CopyTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。