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


C# GZipStream类代码示例

本文整理汇总了C#中GZipStream的典型用法代码示例。如果您正苦于以下问题:C# GZipStream类的具体用法?C# GZipStream怎么用?C# GZipStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Compress

 /// <summary>
 /// 
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] Compress(byte[] data)
 {
     using (var compressedStream = new MemoryStream())
     using (var zipStream = new GZipStream(compressedStream, CompressionMode.Compress))
     {
         zipStream.Write(data, 0, data.Length);
         zipStream.Close();
         return compressedStream.ToArray();
     }
 }
开发者ID:heyjohnnyc,项目名称:mikulus,代码行数:15,代码来源:ByteArrayUtilities.cs

示例2: Compress_Canterbury

 public void Compress_Canterbury(int innerIterations, string fileName, CompressionLevel compressLevel)
 {
     byte[] bytes = File.ReadAllBytes(Path.Combine("GZTestData", "Canterbury", fileName));
     PerfUtils utils = new PerfUtils();
     FileStream[] filestreams = new FileStream[innerIterations];
     GZipStream[] gzips = new GZipStream[innerIterations];
     string[] paths = new string[innerIterations];
     foreach (var iteration in Benchmark.Iterations)
     {
         for (int i = 0; i < innerIterations; i++)
         {
             paths[i] = utils.GetTestFilePath();
             filestreams[i] = File.Create(paths[i]);
         }
         using (iteration.StartMeasurement())
             for (int i = 0; i < innerIterations; i++)
             {
                 gzips[i] = new GZipStream(filestreams[i], compressLevel);
                 gzips[i].Write(bytes, 0, bytes.Length);
                 gzips[i].Flush();
                 gzips[i].Dispose();
                 filestreams[i].Dispose();
             }
         for (int i = 0; i < innerIterations; i++)
             File.Delete(paths[i]);
     }
 }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:27,代码来源:Perf.GZipStream.cs

示例3: Assemble

    static void Assemble(List<string> files, string destinationDirectory)
    {
        string fileOutputPath = destinationDirectory + "assembled" + "." + matches[0].Groups[3];
        var fsSource = new FileStream(fileOutputPath, FileMode.Create);
        fsSource.Close();

        using (fsSource = new FileStream(fileOutputPath, FileMode.Append))
        {
            // reading the file paths of the parts from the files list
            foreach (var filePart in files)
            {
                using (var partSource = new FileStream(filePart, FileMode.Open))
                {
                    using (var compressionStream = new GZipStream(partSource,CompressionMode.Decompress,false))
                    {
                        // copy the bytes from part to new assembled file
                        Byte[] bytePart = new byte[4096];
                        while (true)
                        {
                            int readBytes = compressionStream.Read(bytePart, 0, bytePart.Length);
                            if (readBytes == 0)
                            {
                                break;
                            }

                            fsSource.Write(bytePart, 0, readBytes);
                        }
                    }
                }
            }
        }
    }
开发者ID:sokito,项目名称:Softuni,代码行数:32,代码来源:ZipingSlicedFiles.cs

示例4: Main

    static void Main()
    {
        var sw = Stopwatch.StartNew();

        using (var inputFile = File.OpenRead("ClassLibrary45.csv.gz"))
        {
            using (var gzip = new GZipStream(inputFile, CompressionMode.Decompress))
            {
                using (var sr = new StreamReader(gzip))
                {
                    var data =
                        from rawLine in sr.ReadToEnd().Split('\n')
                            let line = rawLine.Trim()
                        where !string.IsNullOrEmpty(line) && !line.StartsWith("//")
                            let parts = line.Split(',')
                        select new
                        {
                            ClassName = parts.First(),
                            ContentId = parts.Last()
                        };

                    var classes = data.ToDictionary(c => c.ClassName, c => c.ContentId);
                    Console.WriteLine("{0} classes loaded.", classes.Count);
                }
            }
        }

        sw.Stop();
        Console.WriteLine("Elapsed: {0} milliseconds.", sw.ElapsedMilliseconds);
    }
开发者ID:yallie,项目名称:MsdnHelper,代码行数:30,代码来源:ClassLibrary45.cs

示例5: Assemble

    static void Assemble(string[] files, string destinationDirectory)
    {
        using (var assemly = new FileStream(destinationDirectory + GetFileName() + "-Assembled" + GetExtention(), FileMode.Create))
        {
            for (int i = 0; i < files.Length; i++)
            {
                using (var source = new FileStream(filePartsNames[i] + ".gz", FileMode.Open))
                {
                    using (var gz = new GZipStream(source, CompressionMode.Decompress))
                    {
                        byte[] buffer = new byte[4096];

                        while (true)
                        {
                            int readBytes = gz.Read(buffer, 0, buffer.Length);
                            if (readBytes == 0)
                            {
                                break;
                            }
                            assemly.Write(buffer, 0, buffer.Length);
                        }
                    }
                }
            }
        }
    }
开发者ID:TheTypoMaster,项目名称:Homework-And-Solved-Problems,代码行数:26,代码来源:Zipping+Sliced+Files.cs

示例6: Assemble

    private static void Assemble(List<string> file, string name, string destinationDir)
    {
        Directory.CreateDirectory(destinationDir);
        FileStream write = new FileStream(destinationDir + name, FileMode.Append);

        byte[] buffer = new byte[4096];
        using (write)
        {
            for (int i = 0; i < file.Count; i++)
            {
                using (FileStream reader = new FileStream("../dir/" + file[i], FileMode.Open))
                {
                    using (GZipStream gz = new GZipStream(reader, CompressionMode.Decompress, false))
                    {
                        while (true)
                        {
                            int bytes = gz.Read(buffer, 0, buffer.Length);
                            if (bytes == 0)
                            {
                                break;
                            }
                            write.Write(buffer, 0, bytes);
                        }
                    }
                }
            }
        }
    }
开发者ID:EBojilova,项目名称:SoftUni-3,代码行数:28,代码来源:Program.cs

示例7: Main

    static void Main(string[] args)
    {
        if (args.Length < 1)
        {
            usage();
            return;
        }
        else
        {
            string inputFile = args[0];
            string outputFile = inputFile + ".gz";

            try
            {
                // Get bytes from input stream
                FileStream inFileStream = new FileStream(Path.Combine(Environment.CurrentDirectory, inputFile), FileMode.Open);
                byte[] buffer = new byte[inFileStream.Length];
                inFileStream.Read(buffer, 0, buffer.Length);
                inFileStream.Close();

                // Create GZip file stream and compress input bytes
                FileStream outFileStream = new FileStream(Path.Combine(Environment.CurrentDirectory, outputFile), FileMode.Create);
                GZipStream compressedStream = new GZipStream(outFileStream, CompressionMode.Compress);
                compressedStream.Write(buffer, 0, buffer.Length);
                compressedStream.Close();
                outFileStream.Close();

                Console.WriteLine("The file has been compressed.  UR Da Bomb!!!");
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Error: Specified file cannot be found.");
            }
        }
    }
开发者ID:rtipton,项目名称:CSharp-Demos-1,代码行数:35,代码来源:Program.cs

示例8: SliceGZip

    private static void SliceGZip(string sourceFile, string destinationDir, int numParts)
    {
        FileInfo fileInfo = new FileInfo(sourceFile);

        int size = (int)fileInfo.Length;
        int partSize = size / numParts;
        int lastPartSize = size - (numParts - 1) * partSize;

        string name = fileInfo.Name;
        string[] nameExtArr = name.Split('.');

        FileStream source = new FileStream(sourceFile, FileMode.Open);
        source.Seek(0, SeekOrigin.Current);
        for (int i = 0; i < numParts; i++)
        {
            int currentSize = (i == (numParts - 1)) ? lastPartSize : partSize;

            byte[] buffer = new byte[currentSize];
            source.Read(buffer, 0, currentSize);

            string currentFilePath = destinationDir + "Part-" + i + "." + nameExtArr[1] + ".gz";
            using (FileStream dest = new FileStream(currentFilePath, FileMode.Create))
            using (GZipStream gzipDest = new GZipStream(dest, CompressionMode.Compress, false))
                gzipDest.Write(buffer, 0, currentSize);

        }
        source.Close();
    }
开发者ID:IvoArsov,项目名称:Advanced-CSharp-Course,代码行数:28,代码来源:ZippingSlicedFiles.cs

示例9: CompressedFiles

        /// <summary>
        /// Yields an Enumerable list of paths to GZTestData files
        /// </summary>
        public static IEnumerable<object[]> CompressedFiles()
        {
            if (_compressedFiles == null)
            {
                _compressedFiles = new List<object[]>();
                // Crypto random data
                byte[] bytes = new byte[100000000];
                var rand = RandomNumberGenerator.Create();
                rand.GetBytes(bytes);
                string filePath = PerfUtils.GetTestFilePath() + ".gz";
                using (FileStream output = File.Create(filePath))
                using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                    zip.Write(bytes, 0, bytes.Length);
                _compressedFiles.Add(new object[] { filePath });

                // Create a compressed file with repeated segments
                bytes = Text.Encoding.UTF8.GetBytes(PerfUtils.CreateString(100000));
                filePath = PerfUtils.GetTestFilePath() + ".gz";
                using (FileStream output = File.Create(filePath))
                using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                    for (int i = 0; i < 1000; i++)
                        zip.Write(bytes, 0, bytes.Length);
                _compressedFiles.Add(new object[] { filePath });
            }
            return _compressedFiles;
        }
开发者ID:sky7sea,项目名称:corefx,代码行数:29,代码来源:Perf.DeflateStream.cs

示例10: AssembleGZip

    private static void AssembleGZip(List<string> files, string destinationDirectory)
    {
        string[] dotItems = files[0].Split('.');
        string ext = dotItems[dotItems.Length - 2];

        string destinationFile = destinationDirectory + "assembled." + ext;
        using (FileStream dest = new FileStream(destinationFile, FileMode.Append, FileAccess.Write))
        {

            foreach (string inFile in files)
            {
                using (FileStream source = new FileStream(inFile, FileMode.Open))
                {
                    using (GZipStream sourceGZip = new GZipStream(source, CompressionMode.Decompress, false))
                    {
                        byte[] buffer = new byte[4096];
                        int len;
                        while ((len = sourceGZip.Read(buffer, 0, buffer.Length)) > 0)
                            dest.Write(buffer, 0, len);
                    }

                }
            }
        }
    }
开发者ID:IvoArsov,项目名称:Advanced-CSharp-Course,代码行数:25,代码来源:ZippingSlicedFiles.cs

示例11: Assemble

    private static void Assemble(int parts)
    {
        byte[] buffer = new byte[4096];
        for (int i = 1; i <= parts; i++)
        {
            string source = String.Format("../../{0}.gz", i);
            FileStream partOfFile = new FileStream(source, FileMode.Open);
            FileStream assembledFile = new FileStream("../../assembled.txt", FileMode.Append);

            using (partOfFile)
            {
                using (assembledFile)
                {
                    using (GZipStream decompression = new GZipStream(partOfFile, CompressionMode.Decompress))
                    {
                        while (true)
                        {
                            int bytesRead = decompression.Read(buffer, 0, buffer.Length);
                            if (bytesRead == 0)
                            {
                                break;
                            }
                            assembledFile.Write(buffer, 0, bytesRead);
                        }
                    }

                }
            }
        }
    }
开发者ID:petdakov,项目名称:SoftUni-Homeworks,代码行数:30,代码来源:GzipStream.cs

示例12: SplitFile

    public static void SplitFile(string inputFile, int parts, string path)
    {
        byte[] buffer = new byte[4096];
        DirectoryInfo directorySelected = new DirectoryInfo(destination);
        using (Stream originalFile = File.OpenRead(sourceFile))
        {
            int index = 1;
            while (originalFile.Position < originalFile.Length)
            {

                using (Stream compressedFile = File.Create(path + "\\" + index + ".gz"))
                {
                    using (GZipStream compression = new GZipStream(compressedFile, CompressionMode.Compress))
                    {
                        int chunkBytesRead = 0;
                        while (chunkBytesRead < originalFile.Length / parts)
                        {
                            int bytesRead = originalFile.Read(buffer, 0, buffer.Length);

                            if (bytesRead == 0)
                            {
                                break;
                            }
                            chunkBytesRead += bytesRead;

                            compression.Write(buffer, 0, bytesRead);
                        }
                    }

                }
                index++;
            }
        }
    }
开发者ID:petdakov,项目名称:SoftUni-Homeworks,代码行数:34,代码来源:GzipStream.cs

示例13: Compress

	public static void Compress(string text, string outfile)
	{
		byte[] buffer = Encoding.UTF8.GetBytes(text);
		MemoryStream ms = new MemoryStream();
		
		using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true))
		{
			zip.Write(buffer, 0, buffer.Length);
		}

		ms.Position = 0;
		MemoryStream outStream = new MemoryStream();

		byte[] compressed = new byte[ms.Length];
		ms.Read(compressed, 0, compressed.Length);

		byte[] gzBuffer = new byte[compressed.Length + 4];
		System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
		System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);
		
		string MimiBase64 = Convert.ToBase64String (gzBuffer);
		File.WriteAllText (outfile, MimiBase64);
		
		Console.WriteLine ("Base64 string saved as "+outfile+"\n");
		//return Convert.ToBase64String (gzBuffer);
	}
开发者ID:Skons,项目名称:p0wnedShell,代码行数:26,代码来源:CompressString.cs

示例14: Assemble

    static void Assemble(List<string> files, string destinationDirectory)
    {
        using (FileStream combined = new FileStream(destinationDirectory + "combined files" + extensionSource, FileMode.Create))
        {
            for (int file = 0; file < files.Count; file++)
            {
                using (FileStream input = new FileStream(files[file], FileMode.Open))
                {
                    using (GZipStream commpression = new GZipStream(input, CompressionMode.Decompress, false))
                    {
                        byte[] buffer = new byte[4096];

                        while (true)
                        {
                            int readBytes = commpression.Read(buffer, 0, buffer.Length);

                            if (readBytes == 0)
                            {
                                break;
                            }
                            combined.Write(buffer, 0, readBytes);
                        }
                    }
                }
            }
        }
    }
开发者ID:VTeneva,项目名称:Advanced-CSharp-HW,代码行数:27,代码来源:ZippingSlicedFiles.cs

示例15: Compress

 public static byte[] Compress(byte[] b)
 {
     MemoryStream ms = new MemoryStream();
     GZipStream zs = new GZipStream(ms, CompressionMode.Compress);
     zs.Write(b, 0, b.Length);
     return ms.ToArray();
 }
开发者ID:spbooks,项目名称:ASPNETANT1,代码行数:7,代码来源:CompressedViewStatePage.cs


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