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#codec
… codec
[read-only]
A
codec
instance associated with the stream.
hash.accumulator#digest
… binary
[read-only]hash.accumulator#hexdigest
… string
[read-only]stream#identifier
… string
[read-only]
Identifier of the stream.
stream#name
… string
[read-only]
Name of the stream.
hash.accumulator#number
… number
[read-only]stream#readable
… boolean
[read-only]
Indicates whether the stream is readable.
stream#stat
… any
[read-only]
Status of the stream.
stream#writable
… boolean
[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
.