本文整理汇总了C#中System.IO.Compression.GZipStream.CopyToAsync方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.CopyToAsync方法的具体用法?C# GZipStream.CopyToAsync怎么用?C# GZipStream.CopyToAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.GZipStream
的用法示例。
在下文中一共展示了GZipStream.CopyToAsync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeforeDeserialization
public async Task<byte[]> BeforeDeserialization(IEnvelope envelope, byte[] serializedMessage)
{
using (var inputStream = new MemoryStream(serializedMessage))
using (var decompressionStream = new GZipStream(inputStream, CompressionMode.Decompress))
using (var outputStream = new MemoryStream())
{
await decompressionStream.CopyToAsync(outputStream).ConfigureAwait(false);
return outputStream.ToArray();
}
}
示例2: SerializeToStreamAsync
/// <inheritdoc />
protected async override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
using (content)
{
var compressedStream = await content.ReadAsStreamAsync();
using (var uncompressedStream = new GZipStream(compressedStream, CompressionMode.Decompress))
{
await uncompressedStream.CopyToAsync(stream);
}
}
}
示例3: DecompressAsync
/// <summary>
/// Asychronously Decompresses a string using System.IO.Compression.GZipStream
/// </summary>
/// <param name="s">String to decompress</param>
/// <returns>Decompressed string</returns>
public static async Task<string> DecompressAsync(string s)
{
var bytes = Convert.FromBase64String(s);
using (var msi = new MemoryStream(bytes))
using (var mso = new MemoryStream())
{
using (var gs = new GZipStream(msi, CompressionMode.Decompress))
{
await gs.CopyToAsync(mso);
}
return Encoding.Unicode.GetString(mso.ToArray());
}
}
示例4: DownloadTitles
/// <summary>
/// Downloads an xml file from AniDB which contains all of the titles for every anime, and their IDs,
/// and saves it to disk.
/// </summary>
/// <param name="titlesFile">The destination file name.</param>
private async Task DownloadTitles(string titlesFile)
{
_logger.Debug("Downloading new AniDB titles file.");
var client = new WebClient();
await AniDbSeriesProvider.RequestLimiter.Tick();
using (var stream = await client.OpenReadTaskAsync(TitlesUrl))
using (var unzipped = new GZipStream(stream, CompressionMode.Decompress))
using (var writer = File.Open(titlesFile, FileMode.Create, FileAccess.Write))
{
await unzipped.CopyToAsync(writer).ConfigureAwait(false);
}
}
示例5: DecompressAsync
public static async Task<string> DecompressAsync(string input)
{
using (var inputStream = new MemoryStream(Convert.FromBase64String(input)))
{
using (var stream = new GZipStream(inputStream, CompressionMode.Decompress))
{
using (var outputStream = new MemoryStream())
{
await stream.CopyToAsync(outputStream);
var output = outputStream.ToArray();
return Encoding.UTF8.GetString(output, 0, output.Length);
}
}
}
}
示例6: WriteFlotAppAsync
public static async Task WriteFlotAppAsync(Stream output, bool decompress = false)
{
if (!decompress)
{
using (var stream = Assembly.GetAssembly(typeof(FlotWebApp)).GetManifestResourceStream("Metrics.Visualization.index.full.html.gz"))
{
await stream.CopyToAsync(output).ConfigureAwait(false);
}
}
else
{
using (var stream = Assembly.GetAssembly(typeof(FlotWebApp)).GetManifestResourceStream("Metrics.Visualization.index.full.html.gz"))
using (var gzip = new GZipStream(stream, CompressionMode.Decompress))
{
await gzip.CopyToAsync(output).ConfigureAwait(false);
}
}
}
示例7: Decrompress
/// <summary>
/// Decrompresses Given File
/// </summary>
/// <param name="File">File to Decompress</param>
public static async Task<String> Decrompress(String file)
{
FileInfo Info = new FileInfo(file);
string newFileName;
using (FileStream originalFileStream = Info.OpenRead())
{
string currentFile = Info.FullName;
newFileName = currentFile.Remove(currentFile.Length - Info.Extension.Length);
using (FileStream decompressed = File.Create(newFileName))
{
using (GZipStream decompression = new GZipStream(originalFileStream, CompressionMode.Decompress))
{
await decompression.CopyToAsync(decompressed);
}
}
}
Info.Delete();
return newFileName;
}
示例8: Decompress
/// <summary>
/// takes byte array and decompress it into Content
/// </summary>
public async Task Decompress()
{
if (CompressedContent != null && CompressedContent.Length != 0)
{
using (MemoryStream inStream = new MemoryStream(CompressedContent))
using (MemoryStream outStream = new MemoryStream())
{
using (GZipStream gz = new GZipStream(inStream, CompressionMode.Decompress))
{
await gz.CopyToAsync(outStream);
}
Content = Encoding.Unicode.GetString(outStream.ToArray());
}
}
else
{
Content = "";
}
}
示例9: SaveToFile
/// <summary>
/// Saves content of this attachment to a temp file.
/// </summary>
/// <returns></returns>
public async Task<IStorageFile> SaveToFile()
{
var target = await ApplicationData.Current.TemporaryFolder
.CreateFolderAsync("Attachments",
CreationCollisionOption.OpenIfExists);
var file = await target.CreateFileAsync(Key,
CreationCollisionOption.ReplaceExisting);
var value = Value;
var compressed = value.Attribute("Compressed");
var isCompressed = compressed != null && (bool)compressed;
if (!isCompressed)
{
var buffer = CryptographicBuffer
.DecodeFromBase64String(value.Value);
await FileIO.WriteBufferAsync(file, buffer);
}
else
{
var bytes = Convert.FromBase64String(value.Value);
using (var buffer = new MemoryStream(bytes))
using (var gz = new GZipStream(buffer, CompressionMode.Decompress))
using (var output = await file.OpenStreamForWriteAsync())
{
await gz.CopyToAsync(output);
}
}
return file;
}