示例#1
0
        public async Task CopyToAsync(Stream outputStream, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var armoredStream = ArmoredOutputStream(outputStream))
                using (var encryptedStream = EncryptionStream(armoredStream))
                    using (var compressedStream = CompressionStream(encryptedStream))
                    {
                        var signatureGenerator = InitSignature(compressedStream);
                        using (var inputStream = await _file.OpenReadStreamAsync(cancellationToken))
                            using (var literalData = new PgpLiteralDataGenerator().Open(compressedStream, PgpLiteralData.Binary, FileName, DateTime.UtcNow, new byte[1 << 16]))
                            {
                                var length = 0;
                                var buf    = new byte[1 << 16];
                                while ((length = await inputStream.ReadAsync(buf, 0, buf.Length)) > 0)
                                {
                                    await literalData.WriteAsync(buf, 0, length);

                                    signatureGenerator?.Update(buf, 0, length);
                                }

                                signatureGenerator?.Generate()?.Encode(compressedStream);
                            }
                    }
        }