summaryrefslogtreecommitdiff
path: root/node_modules/blake3-wasm/esm/base/hash-instance.js
diff options
context:
space:
mode:
authorakiyamn2023-09-24 23:22:21 +1000
committerakiyamn2023-09-24 23:22:21 +1000
commit4e87195739f2a5d9a05451b48773c8afdc680765 (patch)
tree9cba501844a4a11dcbdffc4050ed8189561c55ed /node_modules/blake3-wasm/esm/base/hash-instance.js
downloadprice-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz
price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip
Initial commit (by create-cloudflare CLI)
Diffstat (limited to 'node_modules/blake3-wasm/esm/base/hash-instance.js')
-rw-r--r--node_modules/blake3-wasm/esm/base/hash-instance.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/node_modules/blake3-wasm/esm/base/hash-instance.js b/node_modules/blake3-wasm/esm/base/hash-instance.js
new file mode 100644
index 0000000..aae7bef
--- /dev/null
+++ b/node_modules/blake3-wasm/esm/base/hash-instance.js
@@ -0,0 +1,57 @@
+import { inputToArray, defaultHashLength } from './hash-fn.js';
+/**
+ * Base implementation of hashing.
+ */
+export class BaseHash {
+ constructor(implementation, alloc, getReader) {
+ this.alloc = alloc;
+ this.getReader = getReader;
+ this.hash = implementation;
+ }
+ /**
+ * @inheritdoc
+ */
+ update(data) {
+ if (!this.hash) {
+ throw new Error('Cannot continue updating hashing after dispose() has been called');
+ }
+ this.hash.update(inputToArray(data));
+ return this;
+ }
+ /**
+ * @inheritdoc
+ */
+ digest({ length = defaultHashLength, dispose = true } = {}) {
+ if (!this.hash) {
+ throw new Error('Cannot call digest() after dipose() has been called');
+ }
+ const digested = this.alloc(length);
+ this.hash.digest(digested);
+ if (dispose) {
+ this.dispose();
+ }
+ return digested;
+ }
+ /**
+ * @inheritdoc
+ */
+ reader({ dispose = true } = {}) {
+ if (!this.hash) {
+ throw new Error('Cannot call reader() after dipose() has been called');
+ }
+ const reader = this.getReader(this.hash.reader());
+ if (dispose) {
+ this.dispose();
+ }
+ return reader;
+ }
+ /**
+ * @inheritdoc
+ */
+ dispose() {
+ var _a;
+ (_a = this.hash) === null || _a === void 0 ? void 0 : _a.free();
+ this.hash = undefined;
+ }
+}
+//# sourceMappingURL=hash-instance.js.map \ No newline at end of file