本文整理汇总了C#中IPackage.ZipToStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IPackage.ZipToStreamAsync方法的具体用法?C# IPackage.ZipToStreamAsync怎么用?C# IPackage.ZipToStreamAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPackage
的用法示例。
在下文中一共展示了IPackage.ZipToStreamAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PutAsync
public async Task<Hash> PutAsync(long id, SemanticVersion version, IPackage package)
{
#region Preconditions
if (package == null) throw new ArgumentNullException(nameof(package));
#endregion
var key = id.ToString() + "/" + version.ToString();
using (var ms = new MemoryStream())
{
await package.ZipToStreamAsync(ms).ConfigureAwait(false);
var hash = Hash.ComputeSHA256(ms, leaveOpen: true);
var blob = new Blob(ms) {
ContentType = "application/zip"
};
await bucket.PutAsync(key, blob).ConfigureAwait(false);
return hash;
}
}
示例2: PutAsync
public async Task<Hash> PutAsync(long id, SemanticVersion version, IPackage package)
{
var key = prefix + id.ToString() + "/" + version.ToString();
using (var ms = new MemoryStream())
{
await package.ZipToStreamAsync(ms).ConfigureAwait(false);
ms.Position = 0;
var hash = Hash.ComputeSHA256(ms, leaveOpen: true);
var secret = SecretKey.Derive(password, hash.Data);
using (var protector = new AesProtector(secret))
{
using (var packageStream = protector.EncryptStream(ms))
{
var blob = new Blob(packageStream) {
ContentType = "application/zip"
};
await bucket.PutAsync(key, blob).ConfigureAwait(false);
}
}
return hash;
}
}