Documentation
¶
Overview ¶
Package ed2k implements an ed2k hasher, as explained in http://wiki.anidb.net/w/Ed2k-hash#How_is_an_ed2k_hash_calculated_exactly.3F.
The ed2k hash is essentially a Merkle tree of depth 1 and fixed BlockSize. Each leaf node's hash is calculated on its own goroutine. Calling Sum() will wait for the hashing goroutines.
Example (HexString) ¶
e := New(false) _, _ = io.Copy(e, strings.NewReader("small example")) fmt.Println(hex.EncodeToString(e.Sum(nil))) // for convenience, ed2k implements Stringer by doing just that fmt.Println(e)
Output: 3e01197bc54364cb86a41738b06ae679 3e01197bc54364cb86a41738b06ae679
Example (NoNullChunk) ¶
e := New(false) _, _ = io.Copy(e, strings.NewReader("small example")) h := e.Sum(nil) fmt.Println(h)
Output: [62 1 25 123 197 67 100 203 134 164 23 56 176 106 230 121]
Index ¶
Examples ¶
Constants ¶
const BlockSize = 9728000
The size of each hash node in bytes.
const Size = md4.Size
The size of the ed2k checksum in bytes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HashCloser ¶
A hash.Hash that also needs to be Close()d when done.
func New ¶
func New(endWithNullChunk bool) HashCloser
New returns a new hash.Hash computing the ed2k checksum.
The bool argument chooses between the new (false) or old (true) blockchain finishing algorithm. The old algorithm was due to an off-by-one bug in the de facto implementation, but is still used in some cases.
In the page given in the package description, false picks the "blue" method, true picks the "red" method.
See hash.Hash for the interface.