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

C# ICompressor类代码示例

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

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



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


示例16: Decompress

		private void Decompress(string sourcePath, string destinationPath, ICompressor compressor)
		{
			using (var originalStream = OpenRead(sourcePath))
			{
				using (var destinationStream = OpenWrite(destinationPath))
				{
					using (compressor)
					{
						using (var compression = compressor.Decompress(originalStream))
						{
							compression.CopyTo(destinationStream);
						}
					}
				}
			}
		}
开发者ID:matteomigliore,项目名称:HSDK,代码行数:16,代码来源:DefaultStorage.cs


示例17: CompressedContent

        /// <summary>
        /// Initializes a new instance of the <see cref="CompressedContent"/> class.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="compressor">The compressor.</param>
        public CompressedContent(HttpContent content, ICompressor compressor)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            if (compressor == null)
            {
                throw new ArgumentNullException("compressor");
            }

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

            this.CopyHeaders();
        }
开发者ID:SneakyMax,项目名称:Microsoft.AspNet.WebApi.MessageHandlers.Compression,代码行数:22,代码来源:CompressedContent.cs


示例18: Compress

        internal override async Task Compress(Func<IDictionary<string, object>, Task> next, OwinContext context, ICompressor compressor, Stream httpOutputStream)
        {
            using (var memoryStream = new MemoryStream())
            {
                using (var compressedStream = compressor.CreateStream(memoryStream))
                {
                    context.Response.Body = compressedStream;
                    await next.Invoke(context.Environment);
                }

                if (memoryStream.Length > 0)
                {
                    SetResponseHeaders(context, compressor, memoryStream);
                    memoryStream.Position = 0;
                    await memoryStream.CopyToAsync(httpOutputStream, BufferSize);
                }
            }
        }
开发者ID:mikegore1000,项目名称:SqueezeMe,代码行数:18,代码来源:DirectCompressionStrategy.cs


示例19: BrokeredMessageFactory

 public BrokeredMessageFactory(MaxLargeMessageSizeSetting maxLargeMessageSize,
                               MaxSmallMessageSizeSetting maxSmallMessageSize,
                               IClock clock,
                               ICompressor compressor,
                               IDispatchContextManager dispatchContextManager,
                               ILargeMessageBodyStore largeMessageBodyStore,
                               ISerializer serializer,
                               ITypeProvider typeProvider)
 {
     _serializer = serializer;
     _maxLargeMessageSize = maxLargeMessageSize;
     _maxSmallMessageSize = maxSmallMessageSize;
     _compressor = compressor;
     _dispatchContextManager = dispatchContextManager;
     _largeMessageBodyStore = largeMessageBodyStore;
     _typeProvider = typeProvider;
     _clock = clock;
 }
开发者ID:fenix2222,项目名称:Nimbus,代码行数:18,代码来源:BrokeredMessageFactory.cs


示例20: CreateStateEntity

        /// <summary>
        /// <paramref name="pageState"/> 정보를 직렬화해서, <see cref="IPageStateEntity"/> 객체로 빌드합니다.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="pageState"></param>
        /// <param name="compressor"></param>
        /// <param name="compressThreshold"></param>
        /// <returns></returns>
        public static IPageStateEntity CreateStateEntity(string id, object pageState, ICompressor compressor,
                                                         int compressThreshold = 40960) {
            compressor.ShouldNotBeNull("compressor");
            compressThreshold.ShouldBePositive("compressThreshold");

            if(IsDebugEnabled)
                log.Debug("상태 정보를 가지는 인스턴스를 생성합니다. pageState=[{0}], compressor=[{1}], compressThreshold=[{2}]",
                          pageState, compressor, compressThreshold);

            if(pageState == null)
                return new PageStateEntity(id, null, false);

            var serializedValue = Serializer.Serialize(pageState);

            if(serializedValue.Length > compressThreshold)
                return new PageStateEntity(id, compressor.Compress(serializedValue), true);

            return new PageStateEntity(id, serializedValue, false);
        }
开发者ID:debop,项目名称:NFramework,代码行数:27,代码来源:PageStateTool.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# IConceptInfo类代码示例发布时间:2022-05-24
下一篇:
C# ICompositionElement类代码示例发布时间: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