Exemple #1
0
        /**
         * Computes the digest by consuming the contents while copying it to an {@link OutputStream}.
         * Returns the computed digest along with the size of the bytes consumed to compute the digest.
         * Does not close the stream.
         *
         * @param contents the contents to compute digest for
         * @param outStream the stream to which the contents are copied
         * @return computed digest and bytes consumed
         * @throws IOException if reading from or writing fails
         */
        public static async Task <BlobDescriptor> ComputeDigestAsync(WritableContentsAsync contents, Stream outStream)
        {
            contents = contents ?? throw new ArgumentNullException(nameof(contents));
            using (CountingDigestOutputStream digestOutStream = new CountingDigestOutputStream(outStream, true))
            {
                await contents(digestOutStream).ConfigureAwait(false);

                return(digestOutStream.ComputeDigest());
            }
        }
Exemple #2
0
 public static IBlob From(WritableContentsAsync writable, long size)
 {
     return(new AsyncWritableContentsBlob(writable, size));
 }
 public AsyncWritableContentsBlob(WritableContentsAsync writableContents, long size)
 {
     this.writableContents = writableContents;
     Size = size;
 }
Exemple #4
0
 /**
  * Computes the digest by consuming the contents.
  *
  * @param contents the contents for which the digest is computed
  * @return computed digest and bytes consumed
  * @throws IOException if reading fails
  */
 public static async Task <BlobDescriptor> ComputeDigestAsync(WritableContentsAsync contents)
 {
     return(await ComputeDigestAsync(contents, Stream.Null).ConfigureAwait(false));
 }