summaryrefslogtreecommitdiff
path: root/cli/bench/testdata/npm/hono/dist/utils/buffer.js
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-08-19 15:54:54 +0530
committerGitHub <noreply@github.com>2022-08-19 15:54:54 +0530
commit25a109d9ea27ad3a76fdce14bba283e953af9bce (patch)
tree68f0280065c9df4be8fa325ba82693879b4b46cd /cli/bench/testdata/npm/hono/dist/utils/buffer.js
parent9e576dff7c39cfd510c60ba92aa0d1c15fd24a6b (diff)
chore(bench): add flash router benchmarks (#15495)
Diffstat (limited to 'cli/bench/testdata/npm/hono/dist/utils/buffer.js')
-rw-r--r--cli/bench/testdata/npm/hono/dist/utils/buffer.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/cli/bench/testdata/npm/hono/dist/utils/buffer.js b/cli/bench/testdata/npm/hono/dist/utils/buffer.js
new file mode 100644
index 000000000..58ee6f9ae
--- /dev/null
+++ b/cli/bench/testdata/npm/hono/dist/utils/buffer.js
@@ -0,0 +1,39 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.bufferToString = exports.timingSafeEqual = exports.equal = void 0;
+const crypto_1 = require("./crypto");
+const equal = (a, b) => {
+ if (a === b) {
+ return true;
+ }
+ if (a.byteLength !== b.byteLength) {
+ return false;
+ }
+ const va = new DataView(a);
+ const vb = new DataView(b);
+ let i = va.byteLength;
+ while (i--) {
+ if (va.getUint8(i) !== vb.getUint8(i)) {
+ return false;
+ }
+ }
+ return true;
+};
+exports.equal = equal;
+const timingSafeEqual = async (a, b, hashFunction) => {
+ if (!hashFunction) {
+ hashFunction = crypto_1.sha256;
+ }
+ const sa = await hashFunction(a);
+ const sb = await hashFunction(b);
+ return sa === sb && a === b;
+};
+exports.timingSafeEqual = timingSafeEqual;
+const bufferToString = (buffer) => {
+ if (buffer instanceof ArrayBuffer) {
+ const enc = new TextDecoder('utf-8');
+ return enc.decode(buffer);
+ }
+ return buffer;
+};
+exports.bufferToString = bufferToString;