Skip to content

Commit

Permalink
@tus/s3-store: Add support to read files (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitjap authored Oct 20, 2023
1 parent 0143aba commit 0f0e5d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/s3-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,14 @@ export class S3Store extends DataStore {
return upload
}

async read(id: string) {
const data = await this.client.getObject({
Bucket: this.bucket,
Key: id,
})
return data.Body as Readable
}

/**
* Write to the file, starting at the provided offset
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/handlers/GetHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class GetHandler extends BaseHandler {
}

// @ts-expect-error exists if supported
const file_stream = this.store.read(id)
const file_stream = await this.store.read(id)
const headers = {'Content-Length': stats.offset}
res.writeHead(200, headers)
return stream.pipeline(file_stream, res, () => {
Expand Down

0 comments on commit 0f0e5d3

Please sign in to comment.