Top Documents Download Gallery Repository
Are you looking for a Software Engineer? Check Here

27hash Module

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)

27.1hash.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.

27.1.1Property

Property Type R/W Explanation
digest binary R Returns the hashed result as binary.
hexdigest string R Returns the hashed result as string in hexadecimal format.
number number R Returns the hashed result as number. This field is valid only for CRC32 and returns `nil` for other hashes.

27.1.2Constructor

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

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

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

27.1.3Method

hash.accumulator#init
hash.accumulator#init():reduce
Initializes the state of the accumulator.

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


Copyright (C) 2011-2017 ypsitau