Skip to content

Commit a8c43d3

Browse files
author
David Frank
committed
readme and test update
1 parent 55bc814 commit a8c43d3

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
1-
# fetch-blob
1+
2+
fetch-blob
3+
==========
4+
5+
[![npm version][npm-image]][npm-url]
6+
[![build status][travis-image]][travis-url]
7+
[![coverage status][codecov-image]][codecov-url]
8+
[![install size][install-size-image]][install-size-url]
29

310
A Blob implementation on node.js, originally from node-fetch
411

5-
See [MDN doc](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and [Tests](https://github.com/bitinn/fetch-blob/blob/master/test.js) for details
12+
## Usage
13+
14+
```sh
15+
$ npm install fetch-blob
16+
```
17+
18+
```js
19+
const Blob = require('fetch-blob');
20+
const fetch = require('node-fetch');
21+
fetch('https://httpbin.org/post', {
22+
method: 'POST',
23+
body: new Blob(['hello'], { type: 'text/plain' })
24+
})
25+
.then(res => res.json()) // expecting a json response
26+
.then(json => console.log(json));
27+
```
28+
29+
See [MDN doc](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and [Tests](https://github.com/bitinn/fetch-blob/blob/master/test.js) for more details.
30+
31+
[npm-image]: https://flat.badgen.net/npm/v/fetch-blob
32+
[npm-url]: https://www.npmjs.com/package/fetch-blob
33+
[travis-image]: https://flat.badgen.net/travis/bitinn/fetch-blob
34+
[travis-url]: https://travis-ci.org/bitinn/fetch-blob
35+
[codecov-image]: https://flat.badgen.net/codecov/c/github/bitinn/fetch-blob/master
36+
[codecov-url]: https://codecov.io/gh/bitinn/fetch-blob
37+
[install-size-image]: https://flat.badgen.net/packagephobia/install/fetch-blob
38+
[install-size-url]: https://packagephobia.now.sh/result?p=fetch-blob

test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,20 @@ test('Blob slice()', async t => {
6868
t.is(await blob2.text(), data.slice(0, 1));
6969
});
7070

71-
test('Blob works with node-fetch Response', async t => {
71+
test('Blob works with node-fetch Response.blob()', async t => {
7272
let data = 'a=1';
7373
let type = 'text/plain';
7474
let blob = new Blob([data], { type });
7575
let res = new Response(blob);
7676
let blob2 = await res.blob();
7777
t.is(await blob2.text(), data);
7878
});
79+
80+
test('Blob works with node-fetch Response.text()', async t => {
81+
let data = 'a=1';
82+
let type = 'text/plain';
83+
let blob = new Blob([data], { type });
84+
let res = new Response(blob);
85+
let text = await res.text();
86+
t.is(text, data);
87+
});

0 commit comments

Comments
 (0)