|
1 | | -# @web-std/blob |
| 1 | +# @web-std/form-data |
2 | 2 |
|
3 | 3 | ![Node.js CI][node.js ci] |
4 | 4 | [![package][version.icon] ![downloads][downloads.icon]][package.url] |
5 | 5 | [![styled with prettier][prettier.icon]][prettier.url] |
6 | 6 |
|
7 | | -Web API compatible [Blob][] for nodejs. |
8 | | - |
9 | | -## Comparison to Alternatives |
10 | | - |
11 | | -#### [fetch-blob][] |
12 | | - |
13 | | -The reason this library exists is because [fetch-blob][] chooses to compromise |
14 | | -Web API compatibility of [`blob.stream()`][w3c blob.stream] by useing nodejs |
15 | | -native [Readable][] stream. We found this to be problematic when sharing code |
16 | | -across nodejs and browser rutimes. Instead this library stays true to the |
17 | | -specification by using [ReadableStream][] implementation from [web-streams-polyfill][] |
18 | | -library even if that is less convinient in nodejs context. |
19 | | - |
20 | | -> Note: Both node [Readable][] streams and web [ReadableStream][] implement |
21 | | -> `AsyncIterable` intreface and in theory either could be used with [for await][] |
22 | | -> loops. In practice however major browsers do not yet ship `AsyncIterable` |
23 | | -> support for [ReadableStream][]s wich in our experience makes choice made by |
24 | | -> [node-fetch][] impractical. |
25 | | -
|
26 | | -[fetch-blob][] is build around node [Buffer][]s. This implementation is built |
27 | | -around standard [Uint8Array][]s. |
28 | | - |
29 | | -[fetch-blob] chooses to use [WeakMap][]s for encapsulating private state. This |
30 | | -library chooses to use to use properties with names that start with `_`. While |
31 | | -those properties aren't truly private they do have better performance profile |
32 | | -and make it possible to interop with this library, which we found impossible |
33 | | -to do with [node-fetch][]. |
34 | | - |
35 | | -### Usage |
36 | | - |
37 | | -```js |
38 | | -import { Blob } from "@web-std/blob" |
39 | | -const blob = new Blob(["hello", new TextEncoder().encode("world")]) |
40 | | -for await (const chunk of blob.stream()) { |
41 | | - console.log(chunk) |
42 | | -} |
43 | | -``` |
44 | | - |
45 | | -### Usage from Typescript |
46 | | - |
47 | | -This library makes use of [typescript using JSDOC annotations][ts-jsdoc] and |
48 | | -also generates type difinitions along with typed definition maps. So you should |
49 | | -be able to get all the type innference out of the box. |
| 7 | +Web API compatible [FormData][] for nodejs. |
50 | 8 |
|
51 | 9 | ## Install |
52 | 10 |
|
53 | | - npm install @web-std/blob |
| 11 | +```sh |
| 12 | +npm install @web-std/form-data |
| 13 | +``` |
54 | 14 |
|
55 | | -[node.js ci]: https://github.com/web-std/blob/workflows/Node.js%20CI/badge.svg |
56 | | -[version.icon]: https://img.shields.io/npm/v/@web-std/blob.svg |
57 | | -[downloads.icon]: https://img.shields.io/npm/dm/@web-std/blob.svg |
58 | | -[package.url]: https://npmjs.org/package/@web-std/blob |
59 | | -[downloads.image]: https://img.shields.io/npm/dm/@web-std/blob.svg |
60 | | -[downloads.url]: https://npmjs.org/package/@web-std/blob |
| 15 | +[node.js ci]: https://github.com/web-std/io/workflows/Node.js%20CI/badge.svg |
| 16 | +[version.icon]: https://img.shields.io/npm/v/@web-std/form-data.svg |
| 17 | +[downloads.icon]: https://img.shields.io/npm/dm/@web-std/form-data.svg |
| 18 | +[package.url]: https://npmjs.org/package/@web-std/form-data |
| 19 | +[downloads.image]: https://img.shields.io/npm/dm/@web-std/form-data.svg |
| 20 | +[downloads.url]: https://npmjs.org/package/@web-std/form-data |
61 | 21 | [prettier.icon]: https://img.shields.io/badge/styled_with-prettier-ff69b4.svg |
62 | 22 | [prettier.url]: https://github.com/prettier/prettier |
63 | | -[blob]: https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob |
64 | | -[fetch-blob]: https://github.com/node-fetch/fetch-blob |
65 | | -[readablestream]: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream |
66 | | -[readable]: https://nodejs.org/api/stream.html#stream_readable_streams |
67 | | -[w3c blob.stream]: https://w3c.github.io/FileAPI/#dom-blob-stream |
68 | | -[web-streams-polyfill]:https://www.npmjs.com/package/web-streams-polyfill |
69 | | -[for await]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of |
70 | | -[buffer]: https://nodejs.org/api/buffer.html |
71 | | -[weakmap]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap |
72 | | -[ts-jsdoc]: https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html |
73 | | -[Uint8Array]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array |
74 | | -[node-fetch]:https://github.com/node-fetch/ |
| 23 | +[FormData]: https://developer.mozilla.org/en-US/docs/Web/API/FormData |
0 commit comments