コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }