public async Task AddAsync <T>(string name, T o, bool overwrite = false) { Uri uri = PackUriHelper.CreatePartUri(new Uri(name, UriKind.Relative)); PackagePart part = _package.PartExists(uri) ? overwrite ? _package.GetPart(uri) : throw new InvalidOperationException("Part already exists") : _package.CreatePart(uri, ""); using Stream output = part.GetStream(); using ICryptoFile ef = IOBuilder.CreateFile(Key, output); await ef.SerializeAsync(o).ConfigureAwait(false); }
public async Task AddAsync(string name, Stream input, bool overwrite = false, IProgress <double> progress = null, CancellationToken cancellationToken = default) { Uri uri = PackUriHelper.CreatePartUri(new Uri(name, UriKind.Relative)); PackagePart part = _package.PartExists(uri) ? overwrite ? _package.GetPart(uri) : throw new IOException("Item already exists") : _package.CreatePart(uri, ""); using Stream output = part.GetStream(); using ICryptoFile ef = IOBuilder.CreateFile(Key, output); await ef.WriteAsync(input, progress, cancellationToken).ConfigureAwait(false); }
public async Task <T> GetAsync <T>(string name) { Uri uri = PackUriHelper.CreatePartUri(new Uri(name, UriKind.Relative)); if (!_package.PartExists(uri)) { throw new FileNotFoundException("The specified item does not exist"); } using Stream input = _package.GetPart(uri).GetStream(); using ICryptoFile ef = IOBuilder.CreateFile(Key, input); return(await ef.DeserializeAsync <T>().ConfigureAwait(false)); }
public async Task GetAsync(string name, Stream output, IProgress <double> progress = null, CancellationToken cancellationToken = default) { Uri uri = PackUriHelper.CreatePartUri(new Uri(name, UriKind.Relative)); if (!_package.PartExists(uri)) { throw new FileNotFoundException("Item does not exist"); } using Stream input = _package.GetPart(uri).GetStream(); using ICryptoFile ef = IOBuilder.CreateFile(Key, input); await ef.ReadAsync(output, progress, cancellationToken).ConfigureAwait(false); }