Skip to content

Commit d4e88ae

Browse files
authored
mention synchronous file read (#26)
It was pointed out that using `fetch()` in a browser today is always asynchronously reading the file, so we should highlight the fact that an import would allow synchronous file reads which is another motivation.
1 parent 9ff572c commit d4e88ae

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Developers will then be able to import the bytes as follows:
1616

1717
```js
1818
import bytes from "./photo.png" with { type: "bytes" };
19-
const bytes = import("./photo.png", { with: { type: "bytes" } });
19+
const bytes = await import("./photo.png", { with: { type: "bytes" } });
2020
```
2121

2222
The bytes are returned as a `Uint8Array` backed by an [immutable arraybuffer](https://github.com/tc39/proposal-immutable-arraybuffer).
@@ -25,7 +25,7 @@ Note: a similar proposal was mentioned in https://github.com/whatwg/html/issues/
2525

2626
## Motivation
2727

28-
In a similar manner to why JSON modules are useful, importing raw bytes is useful to extend this behavior to all files. This proposal provides an isomorphic way to read a file, regardless of the JavaScript environment.
28+
In a similar manner to why JSON modules are useful, importing raw bytes is useful to extend this behavior to all files. This proposal provides an isomorphic way to read a file synchronously or asynchronously, regardless of the JavaScript environment.
2929

3030
For example, a developer may want to read a `.png` file to process an image or `.woff` to process a font and pass the bytes into isomorphic tools like [satori](https://github.com/vercel/satori).
3131

0 commit comments

Comments
 (0)