add blob support

This commit is contained in:
Randall Schmidt
2021-06-11 16:37:51 -04:00
parent 2f5409c25c
commit 3896ae2832
4 changed files with 167 additions and 7 deletions

View File

@ -1,4 +1,5 @@
const stream = require('stream');
const Blob = require('./blob.js');
const Headers = require('./headers.js');
class Response {
@ -27,18 +28,23 @@ class Response {
return this.bodyBuffer;
}
text() {
async text() {
return this.consumeBody().toString();
}
json() {
async json() {
return JSON.parse(this.consumeBody().toString());
}
buffer() {
async buffer() {
return this.consumeBody();
}
async blob() {
const type = this.headers.get('content-type');
return new Blob([this.consumeBody()], { type });
}
ejectFromCache() {
return this.ejectSelfFromCache();
}