Skip to content

Commit

Permalink
Merge branch 'merge' into bricks
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Apr 8, 2024
2 parents 019b181 + 6da74ff commit beed78b
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/utils/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class FileResponse {
this.ok = false;
this.status = 0;
this.statusText = '';
this.body = null;
this._body = null;
}

static async create(filePath) {
Expand All @@ -111,16 +111,6 @@ class FileResponse {
let stats = fs.statSync(response.filePath);
response.headers.set('content-length', stats.size.toString());
response.headers.set('content-type', getMIME(response.filePath));

let self = response;
response.body = new ReadableStream({
start(controller) {
self.arrayBuffer().then(buffer => {
controller.enqueue(new Uint8Array(buffer));
controller.close();
})
}
});
} else {
response.status = 404;
response.statusText = 'Not Found';
Expand All @@ -139,10 +129,27 @@ class FileResponse {
response.status = this.status;
response.statusText = this.statusText;
response.headers = new Headers(this.headers);
response.body = this.body;
return response;
}

get bodyUsed() {
return this._body !== null;
}

get body() {
if (IS_REACT_NATIVE) throw new Error('`body` is not supported in React Native.');
const self = this;
this._body ??= new ReadableStream({
start(controller) {
self.arrayBuffer().then(buffer => {
controller.enqueue(new Uint8Array(buffer));
controller.close();
});
}
});
return this._body;
}

/**
* Reads the contents of the file specified by the filePath property and returns a Promise that
* resolves with an ArrayBuffer containing the file's contents.
Expand Down

0 comments on commit beed78b

Please sign in to comment.