bare-fetch
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -1,2 +0,2 @@ | ||
const { ReadableStream } = require('bare-stream/web') | ||
const { ReadableStream, isReadableStreamDisturbed } = require('bare-stream/web') | ||
const errors = require('./errors') | ||
@@ -8,3 +8,2 @@ | ||
this.body = null | ||
this.bodyUsed = false | ||
@@ -25,9 +24,16 @@ if (typeof body === 'string') body = Buffer.from(body) | ||
// https://fetch.spec.whatwg.org/#dom-body-bodyused | ||
get bodyUsed() { | ||
return this.body !== null && isReadableStreamDisturbed(this.body) | ||
} | ||
async buffer() { | ||
if (this.body === null) { | ||
throw errors.BODY_UNUSABLE('Body is unset') | ||
} | ||
if (this.bodyUsed) { | ||
throw errors.BODY_ALREADY_CONSUMED('Body has already been consumed') | ||
throw errors.BODY_UNUSABLE('Body has already been consumed') | ||
} | ||
this.bodyUsed = true | ||
const chunks = [] | ||
@@ -34,0 +40,0 @@ let length = 0 |
@@ -35,9 +35,5 @@ module.exports = class FetchError extends Error { | ||
static BODY_ALREADY_CONSUMED(msg) { | ||
return new FetchError( | ||
msg, | ||
'BODY_ALREADY_CONSUMED', | ||
FetchError.BODY_ALREADY_CONSUMED | ||
) | ||
static BODY_UNUSABLE(msg) { | ||
return new FetchError(msg, 'BODY_UNUSABLE', FetchError.BODY_UNUSABLE) | ||
} | ||
} |
{ | ||
"name": "bare-fetch", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "WHATWG Fetch implementation for Bare", | ||
@@ -5,0 +5,0 @@ "exports": { |
19294
190