28hash Module

28.1Overview

The hash module provides measures to calculate hash values of a data sequence in a stream. To utilize it, import the hash module using import function.

Below is an example to calculate MD5, SHA-1 and CRC32 hash values of a file named foo.txt.

import(hash)

fileName = 'foo.txt'
println('MD5: ', hash.md5(fileName).hexdigest)
println('SHA-1: ', hash.sha1(fileName).hexdigest)
println('CRC32: ', hash.crc32(fileName).hexdigest)

28.2hash.accumulator Class

The hash.accumulator class provides measures to calculate hashed numbers including MD5, SHA-1 and CRC32.

As the class inhefits from stream, you can call methods of stream class with hash.accumulator instances.

28.2.1Property

The hash.accumulator instance has following properties:

stream#codeccodec [read-only]
A codec instance associated with the stream.
hash.accumulator#digestbinary [read-only]
hash.accumulator#hexdigeststring [read-only]
stream#identifierstring [read-only]
Identifier of the stream.
stream#namestring [read-only]
Name of the stream.
hash.accumulator#numbernumber [read-only]
stream#readableboolean [read-only]
Indicates whether the stream is readable.
stream#statany [read-only]
Status of the stream.
stream#writableboolean [read-only]
Indicates whether the stream is writable.

28.2.2Constructor

hash.md5(stream?:stream:r) {block?}
Creates an hash.accumulator instance that calculates MD5 hashed value from the content of stream.
hash.sha1(stream?:stream:r) {block?}
Creates an hash.accumulator instance that calculates SHA1 hashed value from the content of stream.
hash.crc32(stream?:stream:r) {block?}
Creates an hash.accumulator instance that calculates CRC32 hashed value from the content of stream.

28.2.3Method

hash.accumulator#init():reduce
Initializes the state of the accumulator.
hash.accumulator#update(stream:stream:r):reduce
Updates the accumulator with the content of stream.