upgrade fetch-blob to 1.0.7 (#870)

Co-authored-by: Antoni Kepinski <xxczaki@pm.me>
This commit is contained in:
Konstantin Vyatkin 2020-06-10 15:14:32 -04:00 committed by GitHub
parent e945b6b846
commit 2d796bde76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 14 deletions

9
@types/index.d.ts vendored
View File

@ -2,14 +2,15 @@
/* eslint-disable no-var, import/no-mutable-exports */
import {Agent} from 'http';
import * as Blob from 'fetch-blob';
import { Agent } from 'http';
import { URL, URLSearchParams } from 'url'
import Blob = require('fetch-blob');
type AbortSignal = {
readonly aborted: boolean;
addEventListener(type: "abort", listener: (this: AbortSignal, ev: Event) => any, options?: boolean | { passive?: boolean; once?: boolean; }): void;
removeEventListener(type: "abort", listener: (this: AbortSignal, ev: Event) => any, options?: boolean | { capture?: boolean; }): void;
addEventListener(type: "abort", listener: (this: AbortSignal) => void): void;
removeEventListener(type: "abort", listener: (this: AbortSignal) => void): void;
};
type HeadersInit = Headers | Record<string, string> | Iterable<readonly [string, string]> | Iterable<Iterable<string>>;

View File

@ -1,7 +1,8 @@
import {expectType, expectAssignable} from 'tsd';
import { expectType, expectAssignable } from 'tsd';
import AbortController from 'abort-controller';
import Blob = require('fetch-blob');
import fetch, {Request, Response, Headers, Body, FetchError, AbortError} from '.';
import fetch, { Request, Response, Headers, Body, FetchError, AbortError } from '.';
import * as _fetch from '.';
import __fetch = require('.');
@ -39,7 +40,7 @@ async function run() {
expectType<string>(request.url);
expectType<Headers>(request.headers);
const headers = new Headers({byaka: 'buke'});
const headers = new Headers({ byaka: 'buke' });
expectType<(a: string, b: string) => void>(headers.append);
expectType<(a: string) => string | null>(headers.get);
expectType<(name: string, value: string) => void>(headers.set);
@ -48,7 +49,7 @@ async function run() {
expectType<() => IterableIterator<[string, string]>>(headers.entries);
expectType<() => IterableIterator<[string, string]>>(headers[Symbol.iterator]);
const postRes = await fetch(request, {method: 'POST', headers});
const postRes = await fetch(request, { method: 'POST', headers });
expectType<Blob>(await postRes.blob());
} catch (error) {
if (error instanceof FetchError) {
@ -85,7 +86,7 @@ async function run() {
const request = new Request('url', { signal: abortController.signal });
expectAssignable<Body>(request);
new Headers({'Header': 'value'});
new Headers({ 'Header': 'value' });
// new Headers(['header', 'value']); // should not work
new Headers([['header', 'value']]);
new Headers(new Headers());

View File

@ -67,7 +67,7 @@
},
"dependencies": {
"data-uri-to-buffer": "^3.0.1",
"fetch-blob": "^1.0.6"
"fetch-blob": "^2.0.0"
},
"esm": {
"sourceMap": true,

View File

@ -94,11 +94,10 @@ export default class Body {
*/
async blob() {
const ct = (this.headers && this.headers.get('content-type')) || (this[INTERNALS].body && this[INTERNALS].body.type) || '';
const buf = await consumeBody(this);
const buf = await this.buffer();
return new Blob([], {
type: ct.toLowerCase(),
buffer: buf
return new Blob([buf], {
type: ct
});
}