ed2k

package module
v0.0.0-...-090a5f4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2014 License: MIT Imports: 5 Imported by: 8

README

go-ed2k

Build Status

Go library to calculate ed2k hashes. Comes with sample ed2ksum program that is a rough equivalent to the coreutils md5sum, sha1sum, etc family of programs.

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 := ed2k.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 := ed2k.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

View Source
const BlockSize = 9728000

The size of each hash node in bytes.

View Source
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

type HashCloser interface {
	hash.Hash
	io.Closer
}

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL