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


C# GZipStream.CopyTo方法代码示例

本文整理汇总了C#中System.IO.Compression.GZipStream.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.CopyTo方法的具体用法?C# GZipStream.CopyTo怎么用?C# GZipStream.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Compression.GZipStream的用法示例。


在下文中一共展示了GZipStream.CopyTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Decompress_gz

        static void Decompress_gz(string gz_file)
        {
            FileStream OriginalFileStream = File.OpenRead(gz_file); // This Returns a file stream to read.

            string extension = Path.GetExtension(gz_file); // This Gets the Extension of the File.
            string final_filename = gz_file.Substring(0, gz_file.Length - extension.Length); // Getting the File Name without the File Extension.

            final_filename = final_filename + ".txt";

            FileStream decompressedFileStream = File.Create(final_filename); // Creating a File to Store the Decompressed File

            GZipStream decompressionStream = new GZipStream(OriginalFileStream, CompressionMode.Decompress); // This sets the Decompression of the Original Compressed FileStream.

            decompressionStream.CopyTo(decompressedFileStream); // Copies the Decompressed File Stream to the desired file.

            // Closing all the File Handles
            decompressionStream.Close();
            decompressedFileStream.Close();
            OriginalFileStream.Close();

            // Parsing the Decompressed File.
            Parse_File(final_filename);
            Console.WriteLine("Decompressed File Name is " + final_filename);

            return;
        }
开发者ID:maheshbabugorantla,项目名称:NOAA-Weather-Data-Scraper,代码行数:26,代码来源:Program.cs

示例2: DecompressStream

        /// <summary>
        /// Decompresses stream using GZip. Returns decompressed Stream.
        /// Returns null if stream isn't compressed.
        /// </summary>
        /// <param name="compressedStream">Stream compressed with GZip.</param>
        public static MemoryStream DecompressStream(Stream compressedStream)
        {
            MemoryStream newStream = new MemoryStream();
            compressedStream.Seek(0, SeekOrigin.Begin);

            GZipStream Decompressor = null;
            try
            {
                Decompressor = new GZipStream(compressedStream, CompressionMode.Decompress, true);
                Decompressor.CopyTo(newStream);
            }
            catch (InvalidDataException invdata)
            {
                return null;
            }
            catch(Exception e)
            {
                throw;
            }
            finally
            {
                if (Decompressor != null)
                    Decompressor.Dispose();
            }

            return newStream;
        }
开发者ID:KFreon,项目名称:Useful-C-Sharp-Collection,代码行数:32,代码来源:General.cs

示例3: DecompressFile

        private static void DecompressFile(string file)
        {
            byte[] buffer;
            using (var fileStream = File.OpenRead(file))
            {
                using (var compressedStream = new GZipStream(fileStream, CompressionMode.Decompress))
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        try
                        {
                            compressedStream.CopyTo(memoryStream);
                            memoryStream.Seek(0, SeekOrigin.Begin);
                            buffer = new byte[memoryStream.Length];
                            memoryStream.Read(buffer, 0, (int)memoryStream.Length);
                        }
                        catch (Exception e)
                        {
                            throw;
                        }
                    }
                }
            }

            File.Create(file).Close();
            File.WriteAllBytes(file, buffer);
        }
开发者ID:mikepastore,项目名称:LM_BadGzipResponseCleanup,代码行数:27,代码来源:Program.cs

示例4: Decompress

 /// <inheritdoc />
 public byte[] Decompress(byte[] data)
 {
     var output = new MemoryStream();
     using (var stream = new GZipStream(new MemoryStream(data), CompressionMode.Decompress))
         stream.CopyTo(output);
     return output.ToArray();
 }
开发者ID:dataline-gmbh,项目名称:ExtraStandard,代码行数:8,代码来源:GzipCompressionHandler.cs

示例5: ExtractJsonResponse

        private static string ExtractJsonResponse(WebResponse response)
        {
            GetRateLimits(response);

            var responseStream = response.GetResponseStream();
            if (responseStream == null)
            {
                throw new StackExchangeException("Response stream is empty, unable to continue");
            }

            string json;
            using (var outStream = new MemoryStream())
            {
                using (var zipStream = new GZipStream(responseStream, CompressionMode.Decompress))
                {
                    zipStream.CopyTo(outStream);
                    outStream.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(outStream, Encoding.UTF8))
                    {
                        json = reader.ReadToEnd();
                    }
                }
            }

            return json;
        }
开发者ID:Paul-Hadfield,项目名称:MyWebSite,代码行数:26,代码来源:ApiV21Proxy.cs

示例6: ManagedBitmap

        public ManagedBitmap(string fileName)
        {
            try
            {
                byte[] buffer = new byte[1024];
                using (var fd = new MemoryStream())
                using (Stream csStream = new GZipStream(File.OpenRead(fileName), CompressionMode.Decompress))
                {
                    csStream.CopyTo(fd);
                    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;
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:27,代码来源:ManagedBitmap.cs

示例7: Decompress

        /// <summary>
        /// 
        /// </summary>
        public static void Decompress(this FileInfo fileInfo)
        {
            // Get the stream of the source file.
            using (FileStream inFile = fileInfo.OpenRead())
            {
                // Get original file extension, for example
                // "doc" from report.doc.gz.
                string curFile = fileInfo.FullName;
                string origName = curFile.Remove(curFile.Length -
                        fileInfo.Extension.Length);

                //Create the decompressed file.
                using (FileStream outFile = File.Create(origName))
                {
                    using (GZipStream Decompress = new GZipStream(inFile,
                            CompressionMode.Decompress))
                    {
                        // Copy the decompression stream 
                        // into the output file.
                        Decompress.CopyTo(outFile);

                        Console.WriteLine("Decompressed: {0}", fileInfo.Name);
                    }
                }
            }
        }
开发者ID:rcasady616,项目名称:SeleniumExtensions,代码行数:29,代码来源:FileInfoExtension.cs

示例8: CurrentDomain_AssemblyResolve

        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            var name = new AssemblyName(args.Name).Name.Replace('-', '.');
            if (name.StartsWith(m_rootNamespace)) return null;

            for (int i = 0; i < m_resourceName.Length; ++i)
            {
                if (m_resourceName[i].Contains(name))
                {
                    byte[] buff;

                    using (var comp     = new MemoryStream((byte[])m_resourceMethod[i].GetValue(null, null)))
                    using (var gzip     = new GZipStream(comp, CompressionMode.Decompress))
                    using (var uncomp   = new MemoryStream(4096))
                    {
                        gzip.CopyTo(uncomp);
                        buff = uncomp.ToArray();
                    }

                    return Assembly.Load(buff);
                }
            }

            return null;
        }
开发者ID:RyuaNerin,项目名称:QIT,代码行数:25,代码来源:Resolver.cs

示例9: Open

        public static PssgFile Open(Stream stream)
        {
            PssgFileType fileType = PssgFile.GetPssgType(stream);

            if (fileType == PssgFileType.Pssg)
            {
                return PssgFile.ReadPssg(stream, fileType);
            }
            else if (fileType == PssgFileType.Xml)
            {
                return PssgFile.ReadXml(stream);
            }
            else // CompressedPssg
            {
                using (stream)
                {
                    MemoryStream mStream = new MemoryStream();

                    using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress))
                    {
                        gZipStream.CopyTo(mStream);
                    }

                    mStream.Seek(0, SeekOrigin.Begin);
                    return PssgFile.ReadPssg(mStream, fileType);
                }
            }
        }
开发者ID:BennyKJohnson,项目名称:Ego-Engine-Modding,代码行数:28,代码来源:PssgFile.cs

示例10: Decompress

        /// <summary>
        /// Metodo que descomprime un fichero
        /// </summary>
        /// <param name="fi">Informacion del fichero descomprimido</param>
        public static void Decompress(FileInfo fi)
        {
            // Get the stream of the source file.
            using (var inFile = fi.Open(FileMode.Open, FileAccess.ReadWrite))
            {
                // Get original file extension, for example
                // "doc" from report.doc.gz.
                var curFile = fi.FullName;
                var origName = curFile.Remove(curFile.Length -
                        fi.Extension.Length);

                //Create the decompressed file.
                using (var outFile = File.Create(origName))
                {
                    using (var decompress = new GZipStream(inFile,
                            CompressionMode.Decompress))
                    {
                        // Copy the decompression stream
                        // into the output file.
                        decompress.CopyTo(outFile);
                        decompress.Close();
                    }

                    outFile.Close();
                }

                inFile.Close();
            }
        }
开发者ID:domitienda,项目名称:DomiLibrary,代码行数:33,代码来源:FileHelper.cs

示例11: Uncompress

 public static void Uncompress(Stream input, Stream output)
 {
     using (var zinput = new GZipStream(input, CompressionMode.Decompress, true))
     {
         zinput.CopyTo(output);
     }
 }
开发者ID:clapette,项目名称:BehaviorIsManaged,代码行数:7,代码来源:ZipHelper.cs

示例12: ExtractAssembly

        private static void ExtractAssembly(bool is64bit)
        {
            var p = Path.Combine(OutputPath, is64bit ? "x64" : "x86", "xxhash.dll");
            if(!Directory.Exists(Path.GetDirectoryName(p)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(p));
            }
            if (!File.Exists(p))
            {
                string resourceName = string.Format("XXHashSharp.{0}.xxhash.dll.gz", is64bit ? "x64" : "x86");

                using (var s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                {
                    using (var gz = new GZipStream(s, CompressionMode.Decompress))
                    {
                        using (var fs = new FileStream(p, FileMode.Create, FileAccess.Write))
                        {
                            gz.CopyTo(fs);
                            fs.Flush(true);
                        }
                    }
                }
            }
            LoadLibrary(p);
        }
开发者ID:BrisingrAerowing,项目名称:XXHashSharp,代码行数:25,代码来源:ModuleInitializer.cs

示例13: Engine

        /// <summary>
        ///     <para> --- </para>
        ///     <para> Initializes FFmpeg.exe; Ensuring that there is a copy</para>
        ///     <para> in the clients temp folder & isn't in use by another process.</para>
        /// </summary>
        public Engine()
        {
            string ffmpegDirectory = "" + Path.GetDirectoryName(FFmpegFilePath);

            if (!Directory.Exists(ffmpegDirectory)) Directory.CreateDirectory(ffmpegDirectory);

            if (File.Exists(FFmpegFilePath))
            {
                if (!Document.IsFileLocked(new FileInfo(FFmpegFilePath))) return;

                Process[] ffmpegProcesses = Process.GetProcessesByName("ffmpeg");
                if (ffmpegProcesses.Length > 0)
                    foreach (Process process in ffmpegProcesses)
                    {
                        // pew pew pew...
                        process.Kill();
                        // let it die...
                        Thread.Sleep(200);
                    }
            }
            else
            {
                Stream ffmpegStream = Assembly.GetExecutingAssembly()
                    .GetManifestResourceStream("MediaToolkit.Resources.FFmpeg.exe.gz");

                if (ffmpegStream == null) throw new Exception("FFMpeg GZip stream is null");

                using (var tempFileStream = new FileStream(FFmpegFilePath, FileMode.Create))
                using (var gZipStream = new GZipStream(ffmpegStream, CompressionMode.Decompress))
                {
                    gZipStream.CopyTo(tempFileStream);
                }
            }
        }
开发者ID:usama4,项目名称:MediaToolkit,代码行数:39,代码来源:Engine.cs

示例14: CurrentDomain_AssemblyResolve

        private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            var asm = args.RequestingAssembly ?? Assembly.GetExecutingAssembly();
            string asmname = asm.GetName().Name.Split('.').FirstOrDefault();
            var tgt = new AssemblyName(args.Name);
            var tgtname = asmname + "." + tgt.Name + ".dll";
            var resname = asm.GetManifestResourceNames().FirstOrDefault(n => string.Compare(n, tgtname, true) == 0);
            if (!string.IsNullOrWhiteSpace(resname))
            {
                using (var strm = asm.GetManifestResourceStream(resname))
                {
                    byte[] data = new byte[strm.Length];
                    strm.Read(data, 0, (int)strm.Length);
                    return Assembly.Load(data);
                }
            }

            resname = asm.GetManifestResourceNames().FirstOrDefault(n => string.Compare(n, tgtname + ".gz", true) == 0);
            if (!string.IsNullOrWhiteSpace(resname))
            {
                using (var strm = asm.GetManifestResourceStream(resname))
                using (var decom = new GZipStream(strm, CompressionMode.Decompress, true))
                {
                    byte[] data = null;
                    using (var ms = new MemoryStream())
                    {
                        decom.CopyTo(ms);
                        data = ms.ToArray();
                    }
                    return Assembly.Load(data);
                }
            }

            return null;
        }
开发者ID:Corey-M,项目名称:Misc,代码行数:35,代码来源:Program.cs

示例15: Deserialize

        public static ISavegame Deserialize(Stream stream)
        {
            if (stream == null) throw new ArgumentNullException(nameof(stream));

            if (stream.Position != 0)
                stream.Seek(0, SeekOrigin.Begin);

            var checkBuffer = new byte[2];
            stream.Read(checkBuffer, 0, 2);
            stream.Seek(0, SeekOrigin.Begin);

            if (checkBuffer.SequenceEqual(new byte[] {0x1f, 0x8b}))
            {
                using (var gZipStream = new GZipStream(stream, CompressionMode.Decompress))
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        gZipStream.CopyTo(memoryStream);
                        return Deserialize(Encoding.UTF8.GetString(memoryStream.ToArray()));
                    }
                }
            }

            if (stream is MemoryStream)
            {
                var memoryStream = (MemoryStream) stream;
                return Deserialize(Encoding.UTF8.GetString(memoryStream.ToArray()));
            }

            using (var memoryStream = new MemoryStream())
            {
                stream.CopyTo(memoryStream);
                return Deserialize(Encoding.UTF8.GetString(memoryStream.ToArray()));
            }
        }
开发者ID:ParkitectNexus,项目名称:AssetMagic,代码行数:35,代码来源:SavegameConverter.cs


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