• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# DeflateStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: ProcessNativeResources

    void ProcessNativeResources(bool compress)
    {
        var unprocessedNameMatch = new Regex(@"^(.*\.)?costura(32|64)\.", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
        var processedNameMatch = new Regex(@"^costura(32|64)\.", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

        foreach (var resource in ModuleDefinition.Resources.OfType<EmbeddedResource>())
        {
            var match = unprocessedNameMatch.Match(resource.Name);
            if (match.Success)
            {
                resource.Name = resource.Name.Substring(match.Groups[1].Length).ToLowerInvariant();
                hasUnmanaged = true;
            }

            if (processedNameMatch.IsMatch(resource.Name))
            {
                using (var stream = resource.GetResourceStream())
                {
                    if (compress && resource.Name.EndsWith(".zip"))
                    {
                        using (var compressStream = new DeflateStream(stream, CompressionMode.Decompress))
                        {
                            checksums.Add(resource.Name, CalculateChecksum(compressStream));
                        }
                    }
                    else
                    {
                        checksums.Add(resource.Name, CalculateChecksum(stream));
                    }
                }
            }
        }
    }
开发者ID:rodrigoferrobrti,项目名称:Costura,代码行数:33,代码来源:NativeResources.cs


示例2: 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


示例3: OverlappingFlushAsync_DuringFlushAsync

        public static async Task OverlappingFlushAsync_DuringFlushAsync()
        {
            byte[] buffer = null;
            string testFilePath = gzTestFile("GZTestDocument.pdf");
            using (var origStream = await LocalMemoryStream.readAppFileAsync(testFilePath))
            {
                buffer = origStream.ToArray();
            }

            using (var writeStream = new ManualSyncMemoryStream(false))
            using (var zip = new DeflateStream(writeStream, CompressionMode.Compress))
            {
                Task task = null;
                try
                {
                    writeStream.manualResetEvent.Set();
                    await zip.WriteAsync(buffer, 0, buffer.Length);
                    writeStream.manualResetEvent.Reset();
                    writeStream.WriteHit = false;
                    task = zip.FlushAsync();
                    Assert.True(writeStream.WriteHit);
                    Assert.Throws<InvalidOperationException>(() => { zip.FlushAsync(); }); // "overlapping flushes"
                }
                finally
                {
                    // Unblock Async operations
                    writeStream.manualResetEvent.Set();
                    // The original WriteAsync should be able to complete
                    Assert.True(task.Wait(100 * 500));
                }
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:32,代码来源:DeflateStreamTests.cs


示例4: CompressResponse

    /// <summary>
    /// Compresses the response stream if the browser allows it.
    /// </summary>
    private static MemoryStream CompressResponse(Stream responseStream, HttpApplication app, string key)
    {
        MemoryStream dataStream = new MemoryStream();
        StreamCopy(responseStream, dataStream);
        responseStream.Dispose();

        byte[] buffer = dataStream.ToArray();
        dataStream.Dispose();

        MemoryStream ms = new MemoryStream();
        Stream compress = null;

        if (IsEncodingAccepted(DEFLATE))
        {
          compress = new DeflateStream(ms, CompressionMode.Compress);
          app.Application.Add(key + "enc", DEFLATE);
        }
        else if (IsEncodingAccepted(GZIP))
        {
          compress = new GZipStream(ms, CompressionMode.Compress);
          app.Application.Add(key + "enc", DEFLATE);
        }

        compress.Write(buffer, 0, buffer.Length);
        compress.Dispose();
        return ms;
    }
开发者ID:hugohcn,项目名称:sge_webapp,代码行数:30,代码来源:CompressionModule.cs


示例5: Compress

    public static void Compress(FileInfo fi)
    {
        // Get the stream of the source file.
        using (FileStream inFile = fi.OpenRead())
        {
            // Prevent compressing hidden and already compressed files.
            if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden)
                != FileAttributes.Hidden & fi.Extension != ".cmp")
            {
                // Create the compressed file.
                using (FileStream outFile =
                        File.Create(fi.FullName + ".cmp"))
                {
                    using (DeflateStream Compress =
                        new DeflateStream(outFile,
                        CompressionMode.Compress))
                    {
                        // Copy the source file into
                        // the compression stream.
                        inFile.CopyTo(Compress);

                        Console.WriteLine("Compressed {0} from {1} to {2} bytes.",
                        fi.Name, fi.Length.ToString(), outFile.Length.ToString());
                    }
                }
            }
        }
    }
开发者ID:SebsCodeVault,项目名称:DeflateStream,代码行数:28,代码来源:Program.cs


示例6: 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


示例7: Decompress

    public static byte[] Decompress(byte[] data)
    {
        try
        {
            string result = string.Empty;
            byte[] buffer = { };

            MemoryStream ms = new MemoryStream(data);
            Stream s = new DeflateStream(ms, CompressionMode.Decompress);

            int len = 4096;

            while (true)
            {
                int oldLen = buffer.Length;
                Array.Resize(ref buffer, oldLen + len);
                int size = s.Read(buffer, oldLen, len);
                if (size != len)
                {
                    Array.Resize(ref buffer, buffer.Length - (len - size));
                    break;
                }
                if (size <= 0)
                    break;
            }
            s.Close();

            return buffer;
        }
        catch
        {
            return null;
        }
    }
开发者ID:Siadatian,项目名称:kermanshahchhto.ir,代码行数:34,代码来源:Zipper.cs


示例8: Compress

		// netz.compress.ICompress implementation

		public long Compress(string file, string zipFile)
		{
			long length = -1;
			FileStream ifs = null;
			FileStream ofs = null;
			try
			{
				ifs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read);
				ofs = File.Open(zipFile, FileMode.Create, FileAccess.Write, FileShare.None);
				DeflateStream dos = new DeflateStream(ofs, CompressionMode.Compress, true);
				byte[] buff = new byte[ifs.Length];
				while(true)
				{
					int r = ifs.Read(buff, 0, buff.Length);
					if(r <= 0) break;
					dos.Write(buff, 0, r);
				}
				dos.Flush();
				dos.Close();
				length = ofs.Length;
			}
			finally
			{
				if(ifs != null) ifs.Close();
				if(ofs != null) ofs.Close();
			}
			return length;
		}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-msnet-netz-compressor-madebits,代码行数:30,代码来源:net20comp.cs


示例9: BaseStream1

        public void BaseStream1()
        {
            var writeStream = new MemoryStream();
            var zip = new DeflateStream(writeStream, CompressionMode.Compress);

            Assert.Same(zip.BaseStream, writeStream);
            writeStream.Dispose();
        }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:DeflateStreamTests.cs


示例10: BaseStream2

        public void BaseStream2()
        {
            var ms = new MemoryStream();
            var zip = new DeflateStream(ms, CompressionMode.Decompress);

            Assert.Same(zip.BaseStream, ms);
            ms.Dispose();
        }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:DeflateStreamTests.cs


示例11: CompressCanWrite

        public void CompressCanWrite()
        {
            var ms = new MemoryStream();
            var zip = new DeflateStream(ms, CompressionMode.Compress);
            Assert.True(zip.CanWrite);

            zip.Dispose();
            Assert.False(zip.CanWrite);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:9,代码来源:DeflateStreamTests.cs


示例12: Embed

    private string Embed(string prefix, string fullPath, bool compress)
    {
        var resourceName = String.Format("{0}{1}", prefix, Path.GetFileName(fullPath).ToLowerInvariant());
        if (ModuleDefinition.Resources.Any(x => x.Name == resourceName))
        {
            LogInfo(string.Format("\tSkipping '{0}' because it is already embedded", fullPath));
            return resourceName;
        }

        if (compress)
        {
            resourceName = String.Format("{0}{1}.zip", prefix, Path.GetFileName(fullPath).ToLowerInvariant());
        }

        LogInfo(string.Format("\tEmbedding '{0}'", fullPath));

        var checksum = CalculateChecksum(fullPath);
        var cacheFile = Path.Combine(cachePath, String.Format("{0}.{1}", checksum, resourceName));
        var memoryStream = new MemoryStream();

        if (File.Exists(cacheFile))
        {
            using (var fileStream = File.Open(cacheFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                fileStream.CopyTo(memoryStream);
            }
        }
        else
        {
            using (var cacheFileStream = File.Open(cacheFile, FileMode.CreateNew, FileAccess.Write, FileShare.Read))
            {
                using (var fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    if (compress)
                    {
                        using (var compressedStream = new DeflateStream(memoryStream, CompressionMode.Compress, true))
                        {
                            fileStream.CopyTo(compressedStream);
                        }
                    }
                    else
                    {
                        fileStream.CopyTo(memoryStream);
                    }
                }
                memoryStream.Position = 0;
                memoryStream.CopyTo(cacheFileStream);
            }
        }
        memoryStream.Position = 0;
        streams.Add(memoryStream);
        var resource = new EmbeddedResource(resourceName, ManifestResourceAttributes.Private, memoryStream);
        ModuleDefinition.Resources.Add(resource);

        return resourceName;
    }
开发者ID:kbdavis07,项目名称:Costura,代码行数:56,代码来源:ResourceEmbedder.cs


示例13: DecompressCanRead

        public void DecompressCanRead()
        {
            var ms = new MemoryStream();
            var zip = new DeflateStream(ms, CompressionMode.Decompress);

            Assert.True(zip.CanRead);

            zip.Dispose();
            Assert.False(zip.CanRead);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:DeflateStreamTests.cs


示例14: CanDisposeDeflateStream

        public void CanDisposeDeflateStream()
        {
            var ms = new MemoryStream();
            var zip = new DeflateStream(ms, CompressionMode.Compress);
            zip.Dispose();

            // Base Stream should be null after dispose 
            Assert.Null(zip.BaseStream);

            zip.Dispose(); // Should be a no-op
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:11,代码来源:DeflateStreamTests.cs


示例15: Deflate

    public static byte[] Deflate(this byte[] data)
    {
        using (MemoryStream output = new MemoryStream())
        {
            using (DeflateStream gzip = new DeflateStream(output, CompressionMode.Compress))
            {
                gzip.Write(data, 0, data.Length);
            }

            return output.ToArray();
        }
    }
开发者ID:darrenshrwd,项目名称:elevated-common,代码行数:12,代码来源:CompresionExtensions.cs


示例16: Decompress

    public void Decompress()
    {
        var bytes = CompressToArray();

        using (var memoryStream = new MemoryStream(bytes))
        using (var deflateStream = new DeflateStream(memoryStream, CompressionMode.Decompress))
        using (var reader = new StreamReader(deflateStream))
        {
            string text = reader.ReadToEnd();
            Assert.AreEqual(Text, text);
        }
    }
开发者ID:sq5gvm,项目名称:Unity.IO.Compression,代码行数:12,代码来源:DeflateStreamTests.cs


示例17: WebRequest

    public void WebRequest()
    {
        var bytes = GetHttpBin("http://httpbin.org/deflate");

        using (var memoryStream = new MemoryStream(bytes))
        using (var deflateStream = new DeflateStream(memoryStream, CompressionMode.Decompress))
        using (var reader = new StreamReader(deflateStream))
        {
            string text = reader.ReadToEnd();
            Assert.IsTrue(text.Contains("\"deflated\": true"), "Request was not compressed!");
        }
    }
开发者ID:sq5gvm,项目名称:Unity.IO.Compression,代码行数:12,代码来源:DeflateStreamTests.cs


示例18: CompressToArray

 protected override byte[] CompressToArray()
 {
     using (var memoryStream = new MemoryStream())
     {
         using (var deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress))
         using (var writer = new StreamWriter(deflateStream))
         {
             writer.Write(Text);
         }
         return memoryStream.ToArray();
     }
 }
开发者ID:sq5gvm,项目名称:Unity.IO.Compression,代码行数:12,代码来源:DeflateStreamTests.cs


示例19: BuildAxisOrderBitArray

        public void BuildAxisOrderBitArray()
        {
            if (!File.Exists(EpsgAccessDatabase))
                throw new IgnoreException("Epsg Access Database not found");

            var ba = new BitArray(32768);

            using (var cn = new System.Data.OleDb.OleDbConnection(
                string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0};", EpsgAccessDatabase)))
            {
                cn.Open();
                var cmd = cn.CreateCommand();
                cmd.CommandText = Sql;
                using (var dr = cmd.ExecuteReader())
                {
                    if (dr != null)
                    while (dr.Read())
                    {
                        var code = dr.GetInt32(0);
                        if (code > 32767) continue;
                        ba[code] = true;
                    }
                }
            }

            string enc;
            var buffer = new byte[4096];
            ba.CopyTo(buffer, 0);

            #if NET45
            using (var bufferStream = new MemoryStream(buffer))
            {
                using (var compressedStream = new MemoryStream())
                {
                    using (var s = new DeflateStream(compressedStream, CompressionMode.Compress))
                    {
                        bufferStream.CopyTo(s);
                        compressedStream.Flush();
                    }
                    enc = Convert.ToBase64String(compressedStream.ToArray());
                    Console.WriteLine("Compressed");
                    WriteBlocks(enc);
                }
            }
            #endif
            enc = Convert.ToBase64String(buffer);
            Console.WriteLine("\nUncompressed");
            WriteBlocks(enc);

            Console.WriteLine("\nByte array");
            WriteBytes(buffer, 20);
        }
开发者ID:bertt,项目名称:BruTile,代码行数:52,代码来源:CrsAxisOrderRegistryTest.cs


示例20: ModifyBaseStream

        public async Task ModifyBaseStream()
        {
            var ms = await LocalMemoryStream.readAppFileAsync(gzTestFile("GZTestDocument.txt.gz"));
            var newMs = StripHeaderAndFooter.Strip(ms);

            var zip = new DeflateStream(newMs, CompressionMode.Decompress);
            int size = 1024;
            byte[] bytes = new byte[size];
            zip.BaseStream.Read(bytes, 0, size); // This will throw if the underlying stream is not writable as expected

            zip.BaseStream.Position = 0;
            await zip.BaseStream.ReadAsync(bytes, 0, size);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:13,代码来源:DeflateStreamTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Degree类代码示例发布时间:2022-05-24
下一篇:
C# Definition类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap