deno.land / x / hono@v4.2.5 / utils / buffer.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { sha256 } from './crypto.ts'
export const equal = (a: ArrayBuffer, b: ArrayBuffer) => { 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}
export const timingSafeEqual = async ( a: string | object | boolean, b: string | object | boolean, hashFunction?: Function) => { if (!hashFunction) { hashFunction = sha256 }
const sa = await hashFunction(a) const sb = await hashFunction(b)
if (!sa || !sb) { return false }
return sa === sb && a === b}
export const bufferToString = (buffer: ArrayBuffer): string => { if (buffer instanceof ArrayBuffer) { const enc = new TextDecoder('utf-8') return enc.decode(buffer) } return buffer}
export const bufferToFormData = (arrayBuffer: ArrayBuffer, contentType: string) => { const response = new Response(arrayBuffer, { headers: { 'Content-Type': contentType, }, }) return response.formData()}
hono

Version Info

Tagged at
a month ago