public static BlobDescriptor computeDigest(WritableContents contents, OutputStream outStream)
      throws IOException {
    CountingDigestOutputStream digestOutStream = new CountingDigestOutputStream(outStream);
    contents.writeTo(digestOutStream);
    digestOutStream.flush();
    return digestOutStream.computeDigest();
  }
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
jib-core/src/main/java/com/google/cloud/tools/jib/hash/Digests.java