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


C# ICompressor类代码示例

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


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

示例1: ExecuteFileTests

        private void ExecuteFileTests(ICompressor compressor, string extension, List<string> exclusions)
        {
            // Bung the folder name and extension onto each element - makes it easier in testing membership
            // Since we don't have linq in .net 2 land :}
            for (var i = 0; i < exclusions.Count; i++)
            {
                exclusions[i] = "Compatability Test Files\\" + exclusions[i] + extension;
            }

            var sourceFiles = Directory.GetFiles("Compatability Test Files", "*" + extension);
            Assume.That(sourceFiles.Length, Is.GreaterThan(0), "No matching source files found, nothing to test");

            foreach (var file in Directory.GetFiles("Compatability Test Files", "*" + extension))
            {
                if (exclusions.Contains(file))
                {
                    continue;
                }
                var source = File.ReadAllText(file);
                var expected = File.ReadAllText(file + ".min");

                // Some of the test files have a load of carriage returns at the end, so we should strip those out
                while (expected.EndsWith("\n"))
                {
                    expected = expected.Substring(0, expected.Length - 1);
                }

                // Act
                var actual = compressor.Compress(source);

                // Assert
                Assert.That(actual, Is.EqualTo(expected), file);
            }
        }
开发者ID:wsky,项目名称:yuicompressor,代码行数:34,代码来源:CompatabilityTests.cs

示例2: Performance

        public void Performance(ICompressor compressor)
        {
            results.Add("---------" + compressor.GetType() + "---------");
            byte[] indata = Encoding.UTF8.GetBytes(testData);

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            byte[] result = null;
            foreach (var i in Enumerable.Range(0,100))
            {
                result = compressor.Compress(indata);
            }
            stopwatch.Stop();
            long ticks = stopwatch.ElapsedTicks;
            results.Add("Compress: " +  ticks);

            stopwatch.Reset();
            stopwatch.Start();

            byte[] resurrected;
            foreach (var i in Enumerable.Range(0, 100))
            {
                resurrected = compressor.Decompress(result);
            }
            stopwatch.Stop();
            ticks = stopwatch.ElapsedTicks;
            results.Add("Decompress: " + ticks);
            results.Add("Compression: " + result.Length / (1.0 * indata.Length));
        }
开发者ID:NerdPad,项目名称:OrigoDB,代码行数:29,代码来源:CompressorTests.cs

示例3: GetCompressedContents

        public static string GetCompressedContents(IEnumerable<string> bundle, string basePath, ICompressor compressor)
        {
            var fileList = bundle.ToList();
            var tempLookup = new ConcurrentDictionary<int, string>();
            Parallel.For(0, fileList.Count(), index =>
            {
                var file = fileList[index];
                var filePathName = Path.Combine(basePath, file);
                var fileContents = File.ReadAllText(filePathName, Encoding.UTF8);
                try
                {
                    fileContents = compressor.Compress(fileContents);
                }
                catch (Exception)
                {
                    Log.Warn("Error during compression (using uncompressed file) - " + file);
                }

                tempLookup[index] = fileContents;
            });

            var contents = new StringBuilder();
            for (var index = 0; index < fileList.Count; index++)
            {
                contents.Append(tempLookup[index]);
            }

            return contents.ToString();
        }
开发者ID:opentable,项目名称:SimpleBundler,代码行数:29,代码来源:Utils.cs

示例4: CompressorTaskEngine

 public CompressorTaskEngine(ILog log, ICompressor compressor)
 {
     Log = log;
     this.compressor = compressor;
     this.Encoding = Encoding.Default;
     DeleteSourceFiles = false;
     LineBreakPosition = -1;
 }
开发者ID:hunt3ri,项目名称:DotNet-Yui-Compressor-CDN,代码行数:8,代码来源:CompressorTaskEngine.cs

示例5: CompressorTask

 protected CompressorTask(ICompressor compressor)
 {
     this.logger = new NantLogAdapter();
     this.TaskEngine = new CompressorTaskEngine(logger, compressor) { SetBuildParameters = this.SetBuildParameters };
     this.SourceFiles = new FileSet();
     this.DeleteSourceFiles = false;
     this.LineBreakPosition = -1;
 }
开发者ID:wsky,项目名称:yuicompressor,代码行数:8,代码来源:CompressorTask.cs

示例6: CompressorTaskEngine

 public CompressorTaskEngine(ILog log, ICompressor compressor)
 {
     Log = log;
     this.compressor = compressor;
     this.Encoding = Encoding.Default;
     DeleteSourceFiles = false;
     LineBreakPosition = -1;
     EcmaExceptions = new List<EcmaScriptException>();
 }
开发者ID:vulh91,项目名称:RequireJSDotNet,代码行数:9,代码来源:CompressorTaskEngine.cs

示例7: UploadFileWithCompress

        public static MongoGridFSFileInfo UploadFileWithCompress(this IMongoRepository repository, ICompressor compressor, byte[] data,
                                                                 string remoteFilename) {
            compressor.ShouldNotBeNull("compressor");

            var entry = new CompressedFileItem(compressor.GetType(), compressor.Compress(data));

            using(var stream = new MemoryStream(FileSerializer.Serialize(entry))) {
                return repository.UploadFile(remoteFilename, stream);
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:10,代码来源:MongoTool.GridFS.cs

示例8: CompressResponseNormal

 private static async Task CompressResponseNormal(IOwinContext context, ICompressor tmpCompressor, 
     Stream responseStream, CancellationToken cancellationToken)
 {
     using (var tmpBufferStream = new MemoryStream())
     {
         await tmpCompressor.Compress(context.Response.Body, tmpBufferStream, cancellationToken);
         context.Response.ContentLength = tmpBufferStream.Length;
         await BaseCompressor.Pump(tmpBufferStream, responseStream, cancellationToken);
     }
 }
开发者ID:hoppler,项目名称:OwinCompressionMiddleware,代码行数:10,代码来源:CompressionMiddleware.cs

示例9: CompressedContent

        public CompressedContent(HttpContent content, ICompressor compressor)
        {
            //Ensure.Argument.NotNull(content, "content");
            //Ensure.Argument.NotNull(compressor, "compressor");

            this.content = content;
            this.compressor = compressor;

            AddHeaders();
        }
开发者ID:unipluss,项目名称:UniAlltid.Language,代码行数:10,代码来源:CompressedContent.cs

示例10: Compress_decompression_yields_original_data

 public void Compress_decompression_yields_original_data(ICompressor compressor)
 {
     var randomBytes = new byte[2000];
     new Randomizer().NextBytes(randomBytes);
     var textBytes = Encoding.UTF8.GetBytes(testData);
     foreach (var array in new[]{randomBytes,textBytes})
     {
         var resurrected = compressor.Decompress(compressor.Compress(array));
         CollectionAssert.AreEqual(array, resurrected);
     }
 }
开发者ID:NerdPad,项目名称:OrigoDB,代码行数:11,代码来源:CompressorTests.cs

示例11: DecompressContent

        private static async Task<HttpContent> DecompressContent(HttpContent compressedContent, ICompressor compressor)
        {
            using (compressedContent)
            {
                MemoryStream decompressed = new MemoryStream();
                await compressor.Decompress(await compressedContent.ReadAsStreamAsync(), decompressed);
                var newContent = new StreamContent(decompressed);
                // copy content type so we know how to load correct formatter
                newContent.Headers.ContentType = compressedContent.Headers.ContentType;

                return newContent;
            }
        }
开发者ID:unipluss,项目名称:UniAlltid.Language,代码行数:13,代码来源:DecompressionHandler.cs

示例12: DecompressContentAsync

        private static async Task<HttpContent> DecompressContentAsync(HttpContent compressedContent, ICompressor compressor)
        {
            using (compressedContent)
            {
                var decompressed = new MemoryStream();
                await compressor.Decompress(await compressedContent.ReadAsStreamAsync(), decompressed).ConfigureAwait(true);

                decompressed.Position = 0;
                var newContent = new StreamContent(decompressed);

                newContent.Headers.ContentType = compressedContent.Headers.ContentType;
                return newContent;
            }
        }
开发者ID:oriches,项目名称:Simple.Rest,代码行数:14,代码来源:CompressionHandler.cs

示例13: CompressToHttpOutputStream

        private static async Task CompressToHttpOutputStream(OwinContext context, ICompressor compressor, Stream httpOutputStream, MemoryStream uncompressedStream)
        {
            using (var compressedStream = new MemoryStream())
            {
                using (var compressionStream = compressor.CreateStream(compressedStream))
                {
                    await uncompressedStream.CopyToAsync(compressionStream, BufferSize);
                }

                compressedStream.Position = 0;

                SetResponseHeaders(context, compressor, compressedStream);
                await compressedStream.CopyToAsync(httpOutputStream, BufferSize);
            }
        }
开发者ID:mikegore1000,项目名称:SqueezeMe,代码行数:15,代码来源:ConfigurableCompressionStrategy.cs

示例14: Compression

		public virtual void Compression(string sourcePath, string destinationPath, CompressionMode mode, ICompressor compressor = null)
		{
			compressor = compressor ?? new GzipCompressor();

			switch (mode)
			{
				case CompressionMode.Compress:
					Compress(sourcePath, destinationPath, compressor);
					return;
				case CompressionMode.Decompress:
					Decompress(sourcePath, destinationPath, compressor);
					return;
				default:
					throw new ArgumentException("The compression mode is not valid.", "mode");
			}
		}
开发者ID:matteomigliore,项目名称:HSDK,代码行数:16,代码来源:DefaultStorage.cs

示例15: DecompressContentAsync

        private static async Task<HttpContent> DecompressContentAsync(HttpContent compressedContent, ICompressor compressor)
        {
            using (compressedContent)
            {
                MemoryStream decompressed = new MemoryStream();
                await compressor.Decompress(await compressedContent.ReadAsStreamAsync(), decompressed).ConfigureAwait(false);
                
                // set position back to 0 so it can be read again
                decompressed.Position = 0;

                var newContent = new StreamContent(decompressed);
                // copy content type so we know how to load correct formatter
                newContent.Headers.ContentType = compressedContent.Headers.ContentType;
                return newContent;
            }
        }
开发者ID:isyedakhtar,项目名称:Fabrik.Common,代码行数:16,代码来源:DecompressionHandler.cs


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