本文整理汇总了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);
}
}
示例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));
}
示例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();
}
示例4: CompressorTaskEngine
public CompressorTaskEngine(ILog log, ICompressor compressor)
{
Log = log;
this.compressor = compressor;
this.Encoding = Encoding.Default;
DeleteSourceFiles = false;
LineBreakPosition = -1;
}
示例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;
}
示例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>();
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
示例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");
}
}
示例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;
}
}