diff options
Diffstat (limited to 'cli/js/body.ts')
-rw-r--r-- | cli/js/body.ts | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/cli/js/body.ts b/cli/js/body.ts index a67655ba8..e00cd30b9 100644 --- a/cli/js/body.ts +++ b/cli/js/body.ts @@ -83,14 +83,11 @@ function bufferFromStream(stream: ReadableStreamReader): Promise<ArrayBuffer> { .then( ({ done, value }): void => { if (done) { - stream.releaseLock(); return resolve(concatenate(...parts)); } if (typeof value === "string") { parts.push(encoder.encode(value)); - } else if (value instanceof Uint8Array) { - parts.push(value); } else if (value instanceof ArrayBuffer) { parts.push(new Uint8Array(value)); } else if (!value) { @@ -134,7 +131,6 @@ export const BodyUsedError = export class Body implements domTypes.Body { protected _stream: domTypes.ReadableStream | null; - protected _bodyUsed = false; constructor(protected _bodySource: BodySource, readonly contentType: string) { validateBodyType(this, _bodySource); @@ -164,14 +160,14 @@ export class Body implements domTypes.Body { } get bodyUsed(): boolean { - if (this.body && this._bodyUsed) { + if (this.body && this.body.locked) { return true; } return false; } public async blob(): Promise<domTypes.Blob> { - return new Blob([await this.arrayBuffer()], { type: this.contentType }); + return new Blob([await this.arrayBuffer()]); } // ref: https://fetch.spec.whatwg.org/#body-mixin @@ -318,7 +314,6 @@ export class Body implements domTypes.Body { } public async arrayBuffer(): Promise<ArrayBuffer> { - this._bodyUsed = true; if ( this._bodySource instanceof Int8Array || this._bodySource instanceof Int16Array || @@ -337,6 +332,7 @@ export class Body implements domTypes.Body { const enc = new TextEncoder(); return enc.encode(this._bodySource).buffer as ArrayBuffer; } else if (this._bodySource instanceof ReadableStream) { + // @ts-ignore return bufferFromStream(this._bodySource.getReader()); } else if (this._bodySource instanceof FormData) { const enc = new TextEncoder(); |