Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
960f7e528d | ||
|
|
582880a297 | ||
|
|
c1dd0851d8 | ||
|
|
bec5a3dceb | ||
|
|
6fabfce52f | ||
|
|
4a46def452 | ||
|
|
9a458af871 | ||
|
|
f7e60156a4 | ||
|
|
af2edbd01c | ||
|
|
f4ddd159a4 | ||
|
|
83559d1144 | ||
|
|
8bf6441343 | ||
|
|
1f5258cd79 | ||
|
|
f336a8d182 |
@@ -1,3 +1,8 @@
|
||||
# Lock files
|
||||
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
+5
-3
@@ -1,11 +1,13 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "8"
|
||||
- "10"
|
||||
- "12"
|
||||
- "lts/*"
|
||||
- "node"
|
||||
|
||||
script:
|
||||
- npm run lint
|
||||
- npm run coverage
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
|
||||
+6
-2
@@ -1,14 +1,18 @@
|
||||
|
||||
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
|
||||
|
||||
- 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
|
||||
|
||||
|
||||
@@ -1,38 +1,39 @@
|
||||
|
||||
fetch-blob
|
||||
==========
|
||||
# fetch-blob
|
||||
|
||||
[![npm version][npm-image]][npm-url]
|
||||
[![build status][travis-image]][travis-url]
|
||||
[![coverage status][codecov-image]][codecov-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
|
||||
$ npm install fetch-blob
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const Blob = require('fetch-blob');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
fetch('https://httpbin.org/post', {
|
||||
method: 'POST',
|
||||
body: new Blob(['hello'], { type: 'text/plain' })
|
||||
})
|
||||
.then(res => res.json()) // expecting a json response
|
||||
method: 'POST',
|
||||
body: new Blob(['hello'], { type: 'text/plain' })
|
||||
})
|
||||
.then(res => res.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-url]: https://www.npmjs.com/package/fetch-blob
|
||||
[travis-image]: https://flat.badgen.net/travis/bitinn/fetch-blob
|
||||
[travis-url]: https://travis-ci.org/bitinn/fetch-blob
|
||||
[codecov-image]: https://flat.badgen.net/codecov/c/github/bitinn/fetch-blob/master
|
||||
[codecov-url]: https://codecov.io/gh/bitinn/fetch-blob
|
||||
[travis-image]: https://flat.badgen.net/travis/node-fetch/fetch-blob
|
||||
[travis-url]: https://travis-ci.org/node-fetch/fetch-blob
|
||||
[codecov-image]: https://flat.badgen.net/codecov/c/github/node-fetch/fetch-blob/master
|
||||
[codecov-url]: https://codecov.io/gh/node-fetch/fetch-blob
|
||||
[install-size-image]: https://flat.badgen.net/packagephobia/install/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
|
||||
// (MIT licensed)
|
||||
|
||||
const Stream = require('stream');
|
||||
|
||||
// Fix for "Readable" isn't a named export issue
|
||||
const {Readable} = Stream;
|
||||
const {Readable: ReadableStream} = require('stream');
|
||||
|
||||
const BUFFER = Symbol('buffer');
|
||||
const TYPE = Symbol('type');
|
||||
@@ -71,7 +68,7 @@ class Blob {
|
||||
}
|
||||
|
||||
stream() {
|
||||
const readable = new Readable();
|
||||
const readable = new ReadableStream();
|
||||
readable._read = () => { };
|
||||
readable.push(this[BUFFER]);
|
||||
readable.push(null);
|
||||
Generated
-5358
File diff suppressed because it is too large
Load Diff
+30
-13
@@ -1,32 +1,49 @@
|
||||
{
|
||||
"name": "fetch-blob",
|
||||
"version": "1.0.5",
|
||||
"description": "A Blob implementation on node.js, originally from node-fetch",
|
||||
"main": "blob.js",
|
||||
"version": "1.0.6",
|
||||
"description": "A Blob implementation in Node.js, originally from node-fetch.",
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "ava",
|
||||
"lint": "xo",
|
||||
"test": "xo && ava",
|
||||
"report": "nyc ava",
|
||||
"coverage": "nyc --reporter json --reporter text ava && codecov -f coverage/coverage-final.json"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/bitinn/fetch-blob.git"
|
||||
},
|
||||
"repository": "https://github.com/node-fetch/fetch-blob.git",
|
||||
"keywords": [
|
||||
"blob",
|
||||
"node-fetch"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"author": "David Frank",
|
||||
"license": "MIT",
|
||||
"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": {
|
||||
"ava": "^1.4.1",
|
||||
"codecov": "^3.6.1",
|
||||
"ava": "^3.8.2",
|
||||
"codecov": "^3.7.0",
|
||||
"get-stream": "^5.1.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 @@
|
||||
|
||||
import test from 'ava';
|
||||
import Blob from './blob';
|
||||
import util from 'util';
|
||||
import stream from 'stream';
|
||||
import getStream from 'get-stream';
|
||||
import { Response } from 'node-fetch';
|
||||
|
||||
const TextDecoder = util.TextDecoder;
|
||||
const Readable = stream.Readable;
|
||||
const test = require('ava');
|
||||
const Blob = require('.');
|
||||
const getStream = require('get-stream');
|
||||
const {Response} = require('node-fetch');
|
||||
|
||||
test('Blob ctor', t => {
|
||||
let data = 'a=1';
|
||||
let blob = new Blob([data]);
|
||||
const data = 'a=1';
|
||||
const blob = new Blob([data]); // eslint-disable-line no-unused-vars
|
||||
t.pass();
|
||||
});
|
||||
|
||||
test('Blob size', t => {
|
||||
let data = 'a=1';
|
||||
let blob = new Blob([data]);
|
||||
const data = 'a=1';
|
||||
const blob = new Blob([data]);
|
||||
t.is(blob.size, data.length);
|
||||
});
|
||||
|
||||
test('Blob type', t => {
|
||||
let data = 'a=1';
|
||||
let type = 'text/plain';
|
||||
let blob = new Blob([data], { type });
|
||||
const data = 'a=1';
|
||||
const type = 'text/plain';
|
||||
const blob = new Blob([data], {type});
|
||||
t.is(blob.type, type);
|
||||
});
|
||||
|
||||
test('Blob text()', async t => {
|
||||
let data = 'a=1';
|
||||
let type = 'text/plain';
|
||||
let blob = new Blob([data], { type });
|
||||
const data = 'a=1';
|
||||
const type = 'text/plain';
|
||||
const blob = new Blob([data], {type});
|
||||
t.is(await blob.text(), data);
|
||||
});
|
||||
|
||||
test('Blob arrayBuffer()', async t => {
|
||||
let data = 'a=1';
|
||||
let type = 'text/plain';
|
||||
let blob = new Blob([data], { type });
|
||||
const data = 'a=1';
|
||||
const type = 'text/plain';
|
||||
const blob = new Blob([data], {type});
|
||||
|
||||
let decoder = new TextDecoder('utf-8');
|
||||
let buffer = await blob.arrayBuffer();
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
const buffer = await blob.arrayBuffer();
|
||||
t.is(decoder.decode(buffer), data);
|
||||
});
|
||||
|
||||
test('Blob stream()', async t => {
|
||||
let data = 'a=1';
|
||||
let type = 'text/plain';
|
||||
let blob = new Blob([data], { type });
|
||||
let result = await getStream(blob.stream());
|
||||
const data = 'a=1';
|
||||
const type = 'text/plain';
|
||||
const blob = new Blob([data], {type});
|
||||
const result = await getStream(blob.stream());
|
||||
t.is(result, data);
|
||||
});
|
||||
|
||||
test('Blob toString()', t => {
|
||||
let data = 'a=1';
|
||||
let type = 'text/plain';
|
||||
let blob = new Blob([data], { type });
|
||||
const data = 'a=1';
|
||||
const type = 'text/plain';
|
||||
const blob = new Blob([data], {type});
|
||||
t.is(blob.toString(), '[object Blob]');
|
||||
});
|
||||
|
||||
test('Blob slice()', async t => {
|
||||
let data = 'a=1';
|
||||
let type = 'text/plain';
|
||||
let blob = new Blob([data], { type });
|
||||
let blob2 = blob.slice(0, 1);
|
||||
const data = 'a=1';
|
||||
const type = 'text/plain';
|
||||
const blob = new Blob([data], {type});
|
||||
const blob2 = blob.slice(0, 1);
|
||||
t.is(await blob2.text(), data.slice(0, 1));
|
||||
});
|
||||
|
||||
test('Blob works with node-fetch Response.blob()', async t => {
|
||||
let data = 'a=1';
|
||||
let type = 'text/plain';
|
||||
let blob = new Blob([data], { type });
|
||||
let res = new Response(blob);
|
||||
let blob2 = await res.blob();
|
||||
const data = 'a=1';
|
||||
const type = 'text/plain';
|
||||
const blob = new Blob([data], {type});
|
||||
const response = new Response(blob);
|
||||
const blob2 = await response.blob();
|
||||
t.is(await blob2.text(), data);
|
||||
});
|
||||
|
||||
test('Blob works with node-fetch Response.text()', async t => {
|
||||
let data = 'a=1';
|
||||
let type = 'text/plain';
|
||||
let blob = new Blob([data], { type });
|
||||
let res = new Response(blob);
|
||||
let text = await res.text();
|
||||
const data = 'a=1';
|
||||
const type = 'text/plain';
|
||||
const blob = new Blob([data], {type});
|
||||
const response = new Response(blob);
|
||||
const text = await response.text();
|
||||
t.is(text, data);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user