-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.mts
More file actions
27 lines (20 loc) · 724 Bytes
/
example.mts
File metadata and controls
27 lines (20 loc) · 724 Bytes
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
import { f, storage, isFromCache } from './fetch.mts';
const a = await f('https://szmarczak.com');
const aBytes = await a.bytes();
// Required for demo: readWeb resolved but #onResponse hasn't resumed yet because we resume first
await Promise.resolve();
if (!storage.has('https://szmarczak.com')) {
console.error('[panic] Not cached after 1 tick');
process.exit();
}
const b = await f('https://szmarczak.com');
const bBytes = await b.bytes();
console.log(isFromCache(a), isFromCache(b));
console.log(
aBytes.length,
bBytes.length,
aBytes.length === bBytes.length,
aBytes.every((byte, index) => byte === bBytes[index]),
);
// Inspect metadata
console.log(storage.get('https://szmarczak.com'));