Checksumming with Multiple Algorithms


The checksums.multi vocabulary makes it possible to calculate multiple checksums with just one pass over a data stream.

The multi-checksum tuple holds a sequence of block-checksum instances, such as md5 or sha1. When the initialize-checksum-state method is called on it, a new instance of block-checksum-state is created for all the checksums, and returned as a new multi-state instance. You can then use add-checksum-bytes to stream data to it. When done, call get-checksum to finalize the process, read the resulting checksums and dispose of the tuple in one step. If you want to cancel the work without calling get-checksum, you must dispose of the tuple so that all implementation-specific resources are released.

The checksum-bytes and the checksum-stream methods encapsulate the above protocol, including instantiation and disposal of the multi-state tuple.

Examples
USING: byte-arrays checksums checksums.md5 checksums.multi checksums.sha ; "test" >byte-array { md5 sha1 } <multi-checksum> checksum-bytes .
{ B{ 9 143 107 205 70 33 211 115 202 222 78 131 38 39 180 246 } B{ 169 74 143 229 204 177 155 166 28 76 8 115 211 145 233 135 152 47 187 211 } }