本文整理汇总了C#中ICompressor.Decompress方法的典型用法代码示例。如果您正苦于以下问题:C# ICompressor.Decompress方法的具体用法?C# ICompressor.Decompress怎么用?C# ICompressor.Decompress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICompressor
的用法示例。
在下文中一共展示了ICompressor.Decompress方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
示例2: 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);
}
}
示例3: 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;
}
}
示例4: 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;
}
}
示例5: 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;
}
}
示例6: DecompressContent
/// <summary>
/// Decompresses the compressed HTTP content.
/// </summary>
/// <param name="compressedContent">The compressed HTTP content.</param>
/// <param name="compressor">The compressor.</param>
/// <returns>The decompressed content.</returns>
public async Task<HttpContent> DecompressContent(HttpContent compressedContent, ICompressor compressor)
{
var decompressedContentStream = new MemoryStream();
// Decompress buffered content
using (var ms = new MemoryStream(await compressedContent.ReadAsByteArrayAsync()))
{
await compressor.Decompress(ms, decompressedContentStream).ConfigureAwait(false);
}
// Set position back to 0 so it can be read again
decompressedContentStream.Position = 0;
var decompressedContent = new StreamContent(decompressedContentStream);
// Copy content headers so we know what got sent back
this.CopyHeaders(compressedContent, decompressedContent);
return decompressedContent;
}
开发者ID:iNIC,项目名称:Microsoft.AspNet.WebApi.MessageHandlers.Compression,代码行数:26,代码来源:HttpContentOperations.cs
示例7: TryParseStateEntity
/// <summary>
/// <paramref name="stateEntity"/> 정보를 파싱하여 원본 Page 상태정보를 빌드합니다.
/// </summary>
/// <param name="stateEntity"></param>
/// <param name="compressor"></param>
/// <param name="pageState"></param>
/// <returns></returns>
public static bool TryParseStateEntity(IPageStateEntity stateEntity, ICompressor compressor, out object pageState) {
if(IsDebugEnabled)
log.Debug("상태 정보를 파싱합니다...");
pageState = null;
if(stateEntity == null)
return false;
bool result;
try {
if(stateEntity.Value != null) {
if(IsDebugEnabled)
log.Debug("저장된 상태 정보(stateEntity)의 값이 존재합니다. 값을 로드합니다... entity Id=[{0}]", stateEntity.Id);
var bytes = (stateEntity.IsCompressed)
? compressor.Decompress(stateEntity.Value)
: stateEntity.Value;
pageState = Serializer.Deserialize(bytes);
}
result = (pageState != null);
}
catch(Exception ex) {
if(log.IsWarnEnabled) {
log.Warn("State 정보를 파싱하는데 실패했습니다. stateEntity=[{0}]", stateEntity);
log.Warn(ex);
}
result = false;
}
if(IsDebugEnabled)
log.Debug("저장된 상태 정보를 로드했습니다. 결과=[{0}], StateEntity=[{1}]", result, stateEntity);
return result;
}
示例8: DownloadBackup
/// <summary>
/// Downloads the latest backup set from the Aws service.
/// </summary>
/// <param name="compressor">The compresor to use when decompressing the downloaded file.</param>
/// <returns>The path to the downloaded and decompressed backup file.</returns>
public string DownloadBackup(ICompressor compressor)
{
S3Object latest = this.GetLatestBackupItem();
string path = latest.Key;
if (!String.IsNullOrEmpty(this.Target.AwsPrefix) && path.StartsWith(this.Target.AwsPrefix, StringComparison.OrdinalIgnoreCase))
{
path = path.Substring(this.Target.AwsPrefix.Length);
if (path.StartsWith("/", StringComparison.Ordinal))
{
path = path.Substring(1);
}
}
path = Path.Combine(TempDir, path);
string fileName = Path.GetFileName(path);
if (File.Exists(path))
{
File.Delete(path);
}
TransferInfo info = new TransferInfo()
{
BytesTransferred = 0,
FileName = fileName,
FileSize = 0
};
using (TransferUtility transfer = new TransferUtility(S3Client))
{
TransferUtilityDownloadRequest request = new TransferUtilityDownloadRequest()
.WithBucketName(AwsConfig.BucketName)
.WithFilePath(path)
.WithKey(latest.Key);
request.WriteObjectProgressEvent += (sender, e) =>
{
info.BytesTransferred = e.TransferredBytes;
info.FileSize = e.TotalBytes;
this.Fire(this.TransferProgress, new TransferInfo(info));
};
this.Fire(this.TransferStart, new TransferInfo(info));
transfer.Download(request);
}
this.Fire(this.TransferComplete, new TransferInfo(info));
this.Fire(this.DecompressStart);
string decompressedPath = compressor.Decompress(path);
this.Fire(this.DecompressComplete);
File.Delete(path);
return decompressedPath;
}
示例9: Load
private static SessionStateItem Load(string headerPrefix, string dataPrefix, IMemcachedClient client, string id, bool metaOnly, ICompressor compressor, Logger logger)
{
// Load the header for the item
var header = client.GetWithCas<byte[]>(headerPrefix + id);
if (header.Result == null)
{
return null;
}
// Deserialize the header values
SessionStateItem entry;
using (var ms = new MemoryStream(header.Result))
{
entry = LoadItem(ms);
}
entry.HeadCas = header.Cas;
// Bail early if we are only loading the meta data
if (metaOnly)
{
return entry;
}
// Load the data for the item
var data = client.GetWithCas<byte[]>(dataPrefix + id);
if (data.Result == null)
{
return null;
}
entry.DataCas = data.Cas;
// Deserialize the data
if (compressor == null)
{
if (logger != null)
logger.Info(string.Format("Load data from Session item with id '{0}' with size {1}", id, data.Result.LongLength));
using (var ms = new MemoryStream(data.Result))
{
using (var br = new BinaryReader(ms))
{
entry.Data = SessionStateItemCollection.Deserialize(br);
}
}
}
else
{
using (var input = new MemoryStream(data.Result))
{
var decompressed = compressor.Decompress(input);
if (logger != null)
logger.Info(string.Format("Load data from Session item with id '{0}' with compessed size {1}. Size after decompression is {2}", id, data.Result.LongLength, decompressed.LongLength));
using (var output = new MemoryStream(decompressed))
{
using (var reader = new BinaryReader(output))
{
entry.Data = SessionStateItemCollection.Deserialize(reader);
}
}
}
}
// Return the session entry
return entry;
}
示例10: WarmUpCompressor
private void WarmUpCompressor(ICompressor compressor)
{
var warmUpData = _dataCreator.GenerateTestData(256);
for (var i = 0; i < 64; ++i)
{
var compressedData = compressor.Compress(warmUpData);
var decompressedData = compressor.Decompress(compressedData);
Assert.IsTrue(warmUpData.SequenceEqual(decompressedData));
}
}
示例11: TestCompressor
private void TestCompressor(ICompressor compressor)
{
var data = _dataCreator.GenerateTestData(637);
var compressedData = compressor.Compress(data);
var decompressedData = compressor.Decompress(compressedData);
Assert.IsTrue(data.SequenceEqual(decompressedData));
}
示例12: DoBenchmark
private void DoBenchmark(ICompressor compressor, int dataSize, int batchCount)
{
var data = _dataCreator.GenerateTestData(dataSize);
byte[] compressedData = null, decompressedData = null;
var stopWatch = Stopwatch.StartNew();
for (var i = 0; i < batchCount; ++i)
{
compressedData = compressor.Compress(data);
decompressedData = compressor.Decompress(compressedData);
}
stopWatch.Stop();
var msPerCycle = (double)stopWatch.ElapsedMilliseconds / batchCount;
var compressionRate = (double)compressedData.Length / data.Length;
Console.WriteLine("\t{0} data {1} compressed {2:P1}: {3}ms per cycle",
TextUtils.GetSizeText(data.Length), TextUtils.GetSizeText(compressedData.Length),
compressionRate, msPerCycle);
}
示例13: 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);
}
}
}
}
}