Skip to content

Commit

Permalink
docs: add tsdoc comments to public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYuion committed Aug 16, 2022
1 parent 29ad023 commit 279f89e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
38 changes: 37 additions & 1 deletion src/md5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ interface HasherState {

export class Md5 {

// One time hashing functions
/**
* Hash a UTF8 string on the spot
* @param str String to hash
* @param raw Whether to return the value as an `Int32Array`
*/
public static hashStr(str: string, raw?: false): string;
public static hashStr(str: string, raw: true): Int32Array;
public static hashStr(str: string, raw: boolean = false) {
Expand All @@ -71,6 +75,11 @@ export class Md5 {
.end(raw);
}

/**
* Hash a ASCII string on the spot
* @param str String to hash
* @param raw Whether to return the value as an `Int32Array`
*/
public static hashAsciiStr(str: string, raw?: false): string;
public static hashAsciiStr(str: string, raw: true): Int32Array;
public static hashAsciiStr(str: string, raw: boolean = false) {
Expand Down Expand Up @@ -267,6 +276,9 @@ export class Md5 {
this.start();
}

/**
* Initialise buffer to be hashed
*/
public start() {
this._dataLength = 0;
this._bufferLength = 0;
Expand All @@ -277,6 +289,11 @@ export class Md5 {
// Char to code point to to array conversion:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt
// #Example.3A_Fixing_charCodeAt_to_handle_non-Basic-Multilingual-Plane_characters_if_their_presence_earlier_in_the_string_is_unknown

/**
* Append a UTF8 string to the hash buffer
* @param str String to append
*/
public appendStr(str: string) {
const buf8 = this._buffer8;
const buf32 = this._buffer32;
Expand Down Expand Up @@ -316,6 +333,10 @@ export class Md5 {
return this;
}

/**
* Append an ASCII string to the hash buffer
* @param str String to append
*/
public appendAsciiStr(str: string) {
const buf8 = this._buffer8;
const buf32 = this._buffer32;
Expand All @@ -339,6 +360,10 @@ export class Md5 {
return this;
}

/**
* Append a byte array to the hash buffer
* @param input array to append
*/
public appendByteArray(input: Uint8Array) {
const buf8 = this._buffer8;
const buf32 = this._buffer32;
Expand All @@ -362,6 +387,9 @@ export class Md5 {
return this;
}

/**
* Get the state of the hash buffer
*/
public getState(): HasherState {
const s = this._state;

Expand All @@ -373,6 +401,10 @@ export class Md5 {
};
}

/**
* Override the current state of the hash buffer
* @param state New hash buffer state
*/
public setState(state: HasherState) {
const buf = state.buffer;
const x = state.state;
Expand All @@ -391,6 +423,10 @@ export class Md5 {
}
}

/**
* Hash the current state of the hash buffer and return the result
* @param raw Whether to return the value as an `Int32Array`
*/
public end(raw: boolean = false) {
const bufLen = this._bufferLength;
const buf8 = this._buffer8;
Expand Down
5 changes: 4 additions & 1 deletion src/md5_file_hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export class Md5FileHasher {
this._configureReader();
}


/**
* Hash a blob of data in the worker
* @param blob Data to hash
*/
public hash(blob: any) {
const self = this;

Expand Down
6 changes: 6 additions & 0 deletions src/parallel_hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export class ParallelHasher {
}
}

/**
* Hash a blob of data in the worker
* @param blob Data to hash
* @returns Promise of the Hashed result
*/
public hash(blob: any) {
const self = this;
let promise;
Expand All @@ -55,6 +60,7 @@ export class ParallelHasher {
return promise;
}

/** Terminate any existing hash requests */
public terminate() {
this._ready = false;
this._hashWorker.terminate();
Expand Down

0 comments on commit 279f89e

Please sign in to comment.