Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
960f7e528d | ||
|
|
582880a297 | ||
|
|
c1dd0851d8 | ||
|
|
bec5a3dceb | ||
|
|
6fabfce52f | ||
|
|
4a46def452 | ||
|
|
9a458af871 | ||
|
|
f7e60156a4 | ||
|
|
af2edbd01c | ||
|
|
f4ddd159a4 | ||
|
|
83559d1144 | ||
|
|
8bf6441343 | ||
|
|
1f5258cd79 | ||
|
|
f336a8d182 | ||
|
|
b09fdac531 |
@@ -1,3 +1,8 @@
|
|||||||
|
# Lock files
|
||||||
|
|
||||||
|
package-lock.json
|
||||||
|
yarn.lock
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
+5
-3
@@ -1,11 +1,13 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
|
|
||||||
node_js:
|
node_js:
|
||||||
- "8"
|
- "lts/*"
|
||||||
- "10"
|
|
||||||
- "12"
|
|
||||||
- "node"
|
- "node"
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
- npm run lint
|
||||||
- npm run coverage
|
- npm run coverage
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- node_modules
|
- node_modules
|
||||||
|
|||||||
+10
-2
@@ -1,10 +1,18 @@
|
|||||||
|
|
||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
## v1.0.6
|
||||||
|
|
||||||
|
- Enhance: use upstream Blob directly in typings (#38)
|
||||||
|
- Other: update dependencies
|
||||||
|
|
||||||
|
## v1.0.5
|
||||||
|
|
||||||
|
- Other: no change to code, update dev dependency to address vulnerability reports
|
||||||
|
|
||||||
## v1.0.4
|
## v1.0.4
|
||||||
|
|
||||||
- Other: general code revwrite to pass linting, prepare for `node-fetch` release v3
|
- Other: general code rewrite to pass linting, prepare for `node-fetch` release v3
|
||||||
|
|
||||||
## v1.0.3
|
## v1.0.3
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +1,39 @@
|
|||||||
|
# fetch-blob
|
||||||
fetch-blob
|
|
||||||
==========
|
|
||||||
|
|
||||||
[![npm version][npm-image]][npm-url]
|
[![npm version][npm-image]][npm-url]
|
||||||
[![build status][travis-image]][travis-url]
|
[![build status][travis-image]][travis-url]
|
||||||
[![coverage status][codecov-image]][codecov-url]
|
[![coverage status][codecov-image]][codecov-url]
|
||||||
[![install size][install-size-image]][install-size-url]
|
[![install size][install-size-image]][install-size-url]
|
||||||
|
|
||||||
A Blob implementation on node.js, originally from node-fetch
|
A Blob implementation in Node.js, originally from [node-fetch](https://github.com/node-fetch/node-fetch).
|
||||||
|
|
||||||
## Usage
|
## Installation
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ npm install fetch-blob
|
$ npm install fetch-blob
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Blob = require('fetch-blob');
|
const Blob = require('fetch-blob');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
fetch('https://httpbin.org/post', {
|
fetch('https://httpbin.org/post', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: new Blob(['hello'], { type: 'text/plain' })
|
body: new Blob(['hello'], { type: 'text/plain' })
|
||||||
})
|
})
|
||||||
.then(res => res.json()) // expecting a json response
|
.then(res => res.json());
|
||||||
.then(json => console.log(json));
|
.then(json => console.log(json));
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
See the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and [tests](https://github.com/node-fetch/fetch-blob/blob/master/test.js) for more details.
|
||||||
|
|
||||||
[npm-image]: https://flat.badgen.net/npm/v/fetch-blob
|
[npm-image]: https://flat.badgen.net/npm/v/fetch-blob
|
||||||
[npm-url]: https://www.npmjs.com/package/fetch-blob
|
[npm-url]: https://www.npmjs.com/package/fetch-blob
|
||||||
[travis-image]: https://flat.badgen.net/travis/bitinn/fetch-blob
|
[travis-image]: https://flat.badgen.net/travis/node-fetch/fetch-blob
|
||||||
[travis-url]: https://travis-ci.org/bitinn/fetch-blob
|
[travis-url]: https://travis-ci.org/node-fetch/fetch-blob
|
||||||
[codecov-image]: https://flat.badgen.net/codecov/c/github/bitinn/fetch-blob/master
|
[codecov-image]: https://flat.badgen.net/codecov/c/github/node-fetch/fetch-blob/master
|
||||||
[codecov-url]: https://codecov.io/gh/bitinn/fetch-blob
|
[codecov-url]: https://codecov.io/gh/node-fetch/fetch-blob
|
||||||
[install-size-image]: https://flat.badgen.net/packagephobia/install/fetch-blob
|
[install-size-image]: https://flat.badgen.net/packagephobia/install/fetch-blob
|
||||||
[install-size-url]: https://packagephobia.now.sh/result?p=fetch-blob
|
[install-size-url]: https://packagephobia.now.sh/result?p=fetch-blob
|
||||||
|
|||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
/// <reference lib="dom"/>
|
||||||
|
|
||||||
|
/* global Blob */
|
||||||
|
export = Blob;
|
||||||
+2
-5
@@ -1,10 +1,7 @@
|
|||||||
// Based on https://github.com/tmpvar/jsdom/blob/aa85b2abf07766ff7bf5c1f6daafb3726f2f2db5/lib/jsdom/living/blob.js
|
// Based on https://github.com/tmpvar/jsdom/blob/aa85b2abf07766ff7bf5c1f6daafb3726f2f2db5/lib/jsdom/living/blob.js
|
||||||
// (MIT licensed)
|
// (MIT licensed)
|
||||||
|
|
||||||
const Stream = require('stream');
|
const {Readable: ReadableStream} = require('stream');
|
||||||
|
|
||||||
// Fix for "Readable" isn't a named export issue
|
|
||||||
const {Readable} = Stream;
|
|
||||||
|
|
||||||
const BUFFER = Symbol('buffer');
|
const BUFFER = Symbol('buffer');
|
||||||
const TYPE = Symbol('type');
|
const TYPE = Symbol('type');
|
||||||
@@ -71,7 +68,7 @@ class Blob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stream() {
|
stream() {
|
||||||
const readable = new Readable();
|
const readable = new ReadableStream();
|
||||||
readable._read = () => { };
|
readable._read = () => { };
|
||||||
readable.push(this[BUFFER]);
|
readable.push(this[BUFFER]);
|
||||||
readable.push(null);
|
readable.push(null);
|
||||||
Generated
-5381
File diff suppressed because it is too large
Load Diff
+30
-13
@@ -1,32 +1,49 @@
|
|||||||
{
|
{
|
||||||
"name": "fetch-blob",
|
"name": "fetch-blob",
|
||||||
"version": "1.0.4",
|
"version": "1.0.6",
|
||||||
"description": "A Blob implementation on node.js, originally from node-fetch",
|
"description": "A Blob implementation in Node.js, originally from node-fetch.",
|
||||||
"main": "blob.js",
|
"main": "index.js",
|
||||||
|
"files": [
|
||||||
|
"index.js",
|
||||||
|
"index.d.ts"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "ava",
|
"lint": "xo",
|
||||||
|
"test": "xo && ava",
|
||||||
"report": "nyc ava",
|
"report": "nyc ava",
|
||||||
"coverage": "nyc --reporter json --reporter text ava && codecov -f coverage/coverage-final.json"
|
"coverage": "nyc --reporter json --reporter text ava && codecov -f coverage/coverage-final.json"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": "https://github.com/node-fetch/fetch-blob.git",
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/bitinn/fetch-blob.git"
|
|
||||||
},
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"blob",
|
"blob",
|
||||||
"node-fetch"
|
"node-fetch"
|
||||||
],
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
},
|
||||||
"author": "David Frank",
|
"author": "David Frank",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/bitinn/fetch-blob/issues"
|
"url": "https://github.com/node-fetch/fetch-blob/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/bitinn/fetch-blob#readme",
|
"homepage": "https://github.com/node-fetch/fetch-blob#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ava": "^1.4.1",
|
"ava": "^3.8.2",
|
||||||
"codecov": "^3.5.0",
|
"codecov": "^3.7.0",
|
||||||
"get-stream": "^5.1.0",
|
"get-stream": "^5.1.0",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"nyc": "^14.1.1"
|
"nyc": "^15.0.1",
|
||||||
|
"xo": "^0.30.0"
|
||||||
|
},
|
||||||
|
"xo": {
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": "test.js",
|
||||||
|
"rules": {
|
||||||
|
"node/no-unsupported-features/es-syntax": 0,
|
||||||
|
"node/no-unsupported-features/node-builtins": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,87 +1,81 @@
|
|||||||
|
const test = require('ava');
|
||||||
import test from 'ava';
|
const Blob = require('.');
|
||||||
import Blob from './blob';
|
const getStream = require('get-stream');
|
||||||
import util from 'util';
|
const {Response} = require('node-fetch');
|
||||||
import stream from 'stream';
|
|
||||||
import getStream from 'get-stream';
|
|
||||||
import { Response } from 'node-fetch';
|
|
||||||
|
|
||||||
const TextDecoder = util.TextDecoder;
|
|
||||||
const Readable = stream.Readable;
|
|
||||||
|
|
||||||
test('Blob ctor', t => {
|
test('Blob ctor', t => {
|
||||||
let data = 'a=1';
|
const data = 'a=1';
|
||||||
let blob = new Blob([data]);
|
const blob = new Blob([data]); // eslint-disable-line no-unused-vars
|
||||||
t.pass();
|
t.pass();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Blob size', t => {
|
test('Blob size', t => {
|
||||||
let data = 'a=1';
|
const data = 'a=1';
|
||||||
let blob = new Blob([data]);
|
const blob = new Blob([data]);
|
||||||
t.is(blob.size, data.length);
|
t.is(blob.size, data.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Blob type', t => {
|
test('Blob type', t => {
|
||||||
let data = 'a=1';
|
const data = 'a=1';
|
||||||
let type = 'text/plain';
|
const type = 'text/plain';
|
||||||
let blob = new Blob([data], { type });
|
const blob = new Blob([data], {type});
|
||||||
t.is(blob.type, type);
|
t.is(blob.type, type);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Blob text()', async t => {
|
test('Blob text()', async t => {
|
||||||
let data = 'a=1';
|
const data = 'a=1';
|
||||||
let type = 'text/plain';
|
const type = 'text/plain';
|
||||||
let blob = new Blob([data], { type });
|
const blob = new Blob([data], {type});
|
||||||
t.is(await blob.text(), data);
|
t.is(await blob.text(), data);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Blob arrayBuffer()', async t => {
|
test('Blob arrayBuffer()', async t => {
|
||||||
let data = 'a=1';
|
const data = 'a=1';
|
||||||
let type = 'text/plain';
|
const type = 'text/plain';
|
||||||
let blob = new Blob([data], { type });
|
const blob = new Blob([data], {type});
|
||||||
|
|
||||||
let decoder = new TextDecoder('utf-8');
|
const decoder = new TextDecoder('utf-8');
|
||||||
let buffer = await blob.arrayBuffer();
|
const buffer = await blob.arrayBuffer();
|
||||||
t.is(decoder.decode(buffer), data);
|
t.is(decoder.decode(buffer), data);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Blob stream()', async t => {
|
test('Blob stream()', async t => {
|
||||||
let data = 'a=1';
|
const data = 'a=1';
|
||||||
let type = 'text/plain';
|
const type = 'text/plain';
|
||||||
let blob = new Blob([data], { type });
|
const blob = new Blob([data], {type});
|
||||||
let result = await getStream(blob.stream());
|
const result = await getStream(blob.stream());
|
||||||
t.is(result, data);
|
t.is(result, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Blob toString()', t => {
|
test('Blob toString()', t => {
|
||||||
let data = 'a=1';
|
const data = 'a=1';
|
||||||
let type = 'text/plain';
|
const type = 'text/plain';
|
||||||
let blob = new Blob([data], { type });
|
const blob = new Blob([data], {type});
|
||||||
t.is(blob.toString(), '[object Blob]');
|
t.is(blob.toString(), '[object Blob]');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Blob slice()', async t => {
|
test('Blob slice()', async t => {
|
||||||
let data = 'a=1';
|
const data = 'a=1';
|
||||||
let type = 'text/plain';
|
const type = 'text/plain';
|
||||||
let blob = new Blob([data], { type });
|
const blob = new Blob([data], {type});
|
||||||
let blob2 = blob.slice(0, 1);
|
const blob2 = blob.slice(0, 1);
|
||||||
t.is(await blob2.text(), data.slice(0, 1));
|
t.is(await blob2.text(), data.slice(0, 1));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Blob works with node-fetch Response.blob()', async t => {
|
test('Blob works with node-fetch Response.blob()', async t => {
|
||||||
let data = 'a=1';
|
const data = 'a=1';
|
||||||
let type = 'text/plain';
|
const type = 'text/plain';
|
||||||
let blob = new Blob([data], { type });
|
const blob = new Blob([data], {type});
|
||||||
let res = new Response(blob);
|
const response = new Response(blob);
|
||||||
let blob2 = await res.blob();
|
const blob2 = await response.blob();
|
||||||
t.is(await blob2.text(), data);
|
t.is(await blob2.text(), data);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Blob works with node-fetch Response.text()', async t => {
|
test('Blob works with node-fetch Response.text()', async t => {
|
||||||
let data = 'a=1';
|
const data = 'a=1';
|
||||||
let type = 'text/plain';
|
const type = 'text/plain';
|
||||||
let blob = new Blob([data], { type });
|
const blob = new Blob([data], {type});
|
||||||
let res = new Response(blob);
|
const response = new Response(blob);
|
||||||
let text = await res.text();
|
const text = await response.text();
|
||||||
t.is(text, data);
|
t.is(text, data);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user