Skip to content
File

Blob: samples/webfs/worker.js

javascript24 lines
1// Copyright (c) 2017-2023 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4 
5const dir = await navigator.storage.getDirectory();
6const bundle = await dir.getDirectoryHandle("tmp");
7const file = await bundle.getFileHandle("foo", { create: true });
8const handle = await file.createSyncAccessHandle();
9 
10const enc = new TextEncoder();
11handle.write(enc.encode("Hello World"));
12handle.write(enc.encode("!!!\n"));
13console.log(handle.getSize());
14handle.close();
15 
16const data = await file.getFile();
17console.log(await data.text());
18 
19export default {
20 async fetch(req, env) {
21 return new Response("Hello World\n");
22 }
23};