Skip to content
Myr

buffer.ts

This file

Path

src/utils/buffer.ts

65 lines · 1.2 KiB · TypeScript

Last changed by

perf(utils/buffer): use promise all for better performance (#3031)yasuaki640before adoptiona9e4176

History of this file

Take it

The walk stopped after 200 commits: lines older than 31d2ea4 point at it.

Merge pull request #2769 from honojs/nextYusuke Wadabefore adoptionacd3634

lines 1–5why, one step back
1/**
2 * @module3 * Buffer utility.4 */5

fix(jsx): use self closing tag only if element has no children (#2384)Taku Amanobefore adoption31d2ea4

lines 6–7why, one step back
6import { sha256 } from './crypto'
7

Merge pull request #2769 from honojs/nextYusuke Wadabefore adoptionacd3634

line 8why, one step back
8export const equal = (a: ArrayBuffer, b: ArrayBuffer): boolean => {

fix(jsx): use self closing tag only if element has no children (#2384)Taku Amanobefore adoption31d2ea4

lines 9–32why, one step back
9 if (a === b) {
10 return true11 }12 if (a.byteLength !== b.byteLength) {13 return false14 }1516 const va = new DataView(a)17 const vb = new DataView(b)1819 let i = va.byteLength20 while (i--) {21 if (va.getUint8(i) !== vb.getUint8(i)) {22 return false23 }24 }2526 return true27}2829export const timingSafeEqual = async (30 a: string | object | boolean,31 b: string | object | boolean,32 hashFunction?: Function

Merge pull request #2769 from honojs/nextYusuke Wadabefore adoptionacd3634

line 33why, one step back
33): Promise<boolean> => {

fix(jsx): use self closing tag only if element has no children (#2384)Taku Amanobefore adoption31d2ea4

lines 34–37why, one step back
34 if (!hashFunction) {
35 hashFunction = sha25636 }37

perf(utils/buffer): use promise all for better performance (#3031)yasuaki640before adoptiona9e4176

line 38why, one step back
38 const [sa, sb] = await Promise.all([hashFunction(a), hashFunction(b)])

fix(jsx): use self closing tag only if element has no children (#2384)Taku Amanobefore adoption31d2ea4

lines 39–54why, one step back
39
40 if (!sa || !sb) {41 return false42 }4344 return sa === sb && a === b45}4647export const bufferToString = (buffer: ArrayBuffer): string => {48 if (buffer instanceof ArrayBuffer) {49 const enc = new TextDecoder('utf-8')50 return enc.decode(buffer)51 }52 return buffer53}54

perf(types): add type annotations (#2663)Yusuke Wadabefore adoptione5975ed

lines 55–58why, one step back
55export const bufferToFormData = (
56 arrayBuffer: ArrayBuffer,57 contentType: string58): Promise<FormData> => {

fix(jsx): use self closing tag only if element has no children (#2384)Taku Amanobefore adoption31d2ea4

lines 59–65why, one step back
59 const response = new Response(arrayBuffer, {
60 headers: {61 'Content-Type': contentType,62 },63 })64 return response.formData()65}