Download node_modules/@aws-sdk/hash-node/dist-es/index.js from sweet2004/bot: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/sweet2004/bot/resolve/main/node_modules/%40aws-sdk/hash-node/dist-es/index.js
- Command line
-
hf download hf://spaces/sweet2004/bot/node_modules/@aws-sdk/hash-node/dist-es/index.js
-
curl -L -o index.js https://huggingface.co/spaces/sweet2004/bot/resolve/main/node_modules/%40aws-sdk/hash-node/dist-es/index.js
1.12 kB
| import { fromArrayBuffer, fromString } from "@aws-sdk/util-buffer-from"; | |
| import { toUint8Array } from "@aws-sdk/util-utf8"; | |
| import { Buffer } from "buffer"; | |
| import { createHash, createHmac } from "crypto"; | |
| export class Hash { | |
| constructor(algorithmIdentifier, secret) { | |
| this.algorithmIdentifier = algorithmIdentifier; | |
| this.secret = secret; | |
| this.reset(); | |
| } | |
| update(toHash, encoding) { | |
| this.hash.update(toUint8Array(castSourceData(toHash, encoding))); | |
| } | |
| digest() { | |
| return Promise.resolve(this.hash.digest()); | |
| } | |
| reset() { | |
| this.hash = this.secret | |
| ? createHmac(this.algorithmIdentifier, castSourceData(this.secret)) | |
| : createHash(this.algorithmIdentifier); | |
| } | |
| } | |
| function castSourceData(toCast, encoding) { | |
| if (Buffer.isBuffer(toCast)) { | |
| return toCast; | |
| } | |
| if (typeof toCast === "string") { | |
| return fromString(toCast, encoding); | |
| } | |
| if (ArrayBuffer.isView(toCast)) { | |
| return fromArrayBuffer(toCast.buffer, toCast.byteOffset, toCast.byteLength); | |
| } | |
| return fromArrayBuffer(toCast); | |
| } | |