Esempio n. 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 BlobDescriptor ComputeDigest(WritableContents contents, Stream outStream)
 {
     using (CountingDigestOutputStream digestOutStream = new CountingDigestOutputStream(outStream, true))
     {
         contents.WriteTo(digestOutStream);
         return(digestOutStream.ComputeDigest());
     }
 }
Esempio n. 2
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());
            }
        }