-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.d.ts
85 lines (79 loc) · 2.99 KB
/
stream.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* `murmurhash-native/stream` module.
*
* Example:
*
* ```ts
* import { createHash } from "murmurhash-native/stream"
* import * as fs from "fs"
*
* fs.createReadStream("hash_me.txt")
* .pipe(createHash("murmurhash128x64", {seed: 42, encoding: "hex"}))
* .pipe(fs.createWriteStream("hash_me.txt.hash"))
* ```
*
* If you don't need stream interface prefer to use utilities from the [[incremental]] module.
* @module stream
*/
/***/
import { TransformOptions, Transform } from "stream";
import { Encoding, OutputType,
Endianness, IMurHasher } from "./incremental";
export { Encoding, OutputType, Endianness, IMurHasher };
/**
* Lists available algorithm names for [createHash].
*/
export function getHashes(): string[];
/**
* Constructs a new MurmurHash object that can be used to generate murmurhash digests
* from the data stream.
*
* If algorithm is an instance of a MurmurHash or a serialized object,
* the seed option is being ignored.
*
* @param algorithm one of the available murmurhash algorithms,
* a murmur hasher instance or a serialized object.
* @param options hasher or stream options.
*/
export function createHash(algorithm: string|MurmurHash|MurmurHashSerial, options?: MurmurHashOptions): MurmurHash;
/**
* Constructs a new MurmurHash object that can be used to generate murmurhash digests
* from the data stream.
*
* @param algorithm one of the available murmurhash algorithms.
* @param seed initial hash seed as an unsigned 32-bit integer.
*/
export function createHash(algorithm: string, seed?: number): MurmurHash;
/** Options for createHash */
export interface MurmurHashOptions extends TransformOptions {
/** Initial hash seed as an unsigned 32-bit integer. */
seed?: number;
/** Digest byte order. */
endianness?: Endianness;
}
/** A serialized MurmurHash object representation created by [[MurmurHash.toJSON]] function */
export interface MurmurHashSerial {
type: string;
seed: string;
}
/** An incremental murmur hash utility with additional node's stream.Transform api */
export class MurmurHash extends Transform implements IMurHasher {
/** Size in bytes of the serialized hasher. */
static readonly SERIAL_BYTE_LENGTH: number;
readonly SERIAL_BYTE_LENGTH: number;
constructor(algorithm: string|MurmurHash|MurmurHashSerial, options?: MurmurHashOptions);
constructor(algorithm: string, seed?: number);
copy(target: MurmurHash): MurmurHash;
digest(outputType?: OutputType): number|string|Buffer;
digest(output: Buffer, offset?: number, length?: number): Buffer;
toJSON(): MurmurHashSerial;
serialize(): string;
serialize(output: Buffer, offset?: number): Buffer;
update(data: string|Buffer, encoding?: Encoding): this;
update(data: string|Buffer, encoding: Encoding, callback: (err: Error) => void): void;
update(data: string|Buffer, callback: (err: Error) => void): void;
endianness: Endianness;
readonly isBusy: boolean;
readonly total: number;
protected _handle: IMurHasher;
}