-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
633 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
// Cryptographic hash | ||
export {default as CryptoHashTransform} from './lib/crypto/crypto-hash-transform'; | ||
export {default as CRC32HashTransform} from './lib/crc32/crc32-hash-transform'; | ||
export {default as CRC32CHashTransform} from './lib/crc32c/crc32c-hash-transform'; | ||
export {default as MD5HashTransform} from './lib/md5-wasm/md5-hash-transform'; | ||
|
||
export {NullLoader} from './lib/utils/null-loader'; | ||
export {hexToBase64 as _hexToBase64, toHex as _toHex} from './lib/utils/base64-utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export {default as CryptoHashTransform} from './lib/crypto/crypto-hash-transform'; | ||
export {default as CRC32HashTransform} from './lib/crc32/crc32-hash-transform'; | ||
export {default as CRC32CHashTransform} from './lib/crc32c/crc32c-hash-transform'; | ||
export {default as MD5HashTransform} from './lib/md5-wasm/md5-hash-transform'; | ||
|
||
export {NullLoader} from './lib/utils/null-loader'; | ||
export {hexToBase64 as _hexToBase64, toHex as _toHex} from './lib/utils/base64-utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {IncrementalTransform} from "@loaders.gl/loader-utils"; | ||
|
||
/** | ||
* A transform that calcultes Cryptographic Hash | ||
*/ | ||
export default class CRC32CHashTransform implements IncrementalTransform { | ||
/** | ||
* Atomic hash calculation | ||
* @returns base64 encoded hash | ||
*/ | ||
static hash(input: ArrayBuffer, options?: object): Promise<string>; | ||
static hashSync(input: ArrayBuffer, options?: object): string; | ||
|
||
constructor(options: object); | ||
|
||
write(chunk: ArrayBuffer): ArrayBuffer | null; | ||
|
||
end(): ArrayBuffer | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import CRC32C from './crc32c'; | ||
import {toHex, hexToBase64} from '../utils/base64-utils'; | ||
|
||
export default class CRC32CHashTransform { | ||
static async hash(input, options) { | ||
return CRC32CHashTransform.hashSync(input, options); | ||
} | ||
|
||
static hashSync(input, options) { | ||
const transform = new CRC32CHashTransform(options); | ||
return transform._update(input)._finish(); | ||
} | ||
|
||
constructor(options) { | ||
this.options = options; | ||
this._hash = new CRC32C(options); | ||
} | ||
|
||
/** | ||
* Pass-through. Update the hash and pass the chunk through unharmed | ||
*/ | ||
write(chunk) { | ||
this._update(chunk); | ||
return chunk; | ||
} | ||
|
||
end() { | ||
const hash = this._finish(); | ||
if (this.options.onEnd) { | ||
this.options.onEnd({hash}); | ||
} | ||
return hash; | ||
} | ||
|
||
_update(chunk) { | ||
this._hash.update(chunk); | ||
return this; | ||
} | ||
|
||
_finish() { | ||
const hashValue = this._hash.finalize(); | ||
const hex = toHex(hashValue); | ||
const hash = hexToBase64(hex); | ||
return hash; | ||
} | ||
} |
Oops, something went wrong.