File
Blob: samples/webfs/worker.js
| 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 | |
| 5 | const dir = await navigator.storage.getDirectory(); |
| 6 | const bundle = await dir.getDirectoryHandle("tmp"); |
| 7 | const file = await bundle.getFileHandle("foo", { create: true }); |
| 8 | const handle = await file.createSyncAccessHandle(); |
| 9 | |
| 10 | const enc = new TextEncoder(); |
| 11 | handle.write(enc.encode("Hello World")); |
| 12 | handle.write(enc.encode("!!!\n")); |
| 13 | console.log(handle.getSize()); |
| 14 | handle.close(); |
| 15 | |
| 16 | const data = await file.getFile(); |
| 17 | console.log(await data.text()); |
| 18 | |
| 19 | export default { |
| 20 | async fetch(req, env) { |
| 21 | return new Response("Hello World\n"); |
| 22 | } |
| 23 | }; |