Skip to content

Commit

Permalink
Fix s3 stream (#297)
Browse files Browse the repository at this point in the history
* Fix s3 read stream

* removed stupid test
  • Loading branch information
finnmich authored Dec 18, 2023
1 parent 6db9e78 commit 6606b19
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"eslint.validate": [
"javascript",
Expand Down
4 changes: 1 addition & 3 deletions src/s3/S3Bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ export class S3Bucket {
if (!(await this.objectAvailable(key))) {
throw new Error('Object not available');
}
return (
await this.s3.getObject({Bucket: this.name, Key: key})
).Body?.transformToWebStream();
return (await this.s3.getObject({Bucket: this.name, Key: key})).Body;
}

async objectAvailable(key: string) {
Expand Down
16 changes: 1 addition & 15 deletions test/s3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,6 @@ describe('getOrCreateBucket', () => {
expect(result.Body?.transformToWebStream()).toBeTruthy();
});

it('should be able to retrieve object as stream 2', async () => {
const bucket = await S3Bucket.getOrCreateBucket(
generateRandomBucketName(),
localstackEndpoint
);
const buffer = Buffer.from([8, 6, 7, 5, 3, 0, 9]);
await bucket!.putObject('test', buffer, 'image/png');
const result = await bucket!.getObjectStream('test');
//TODO: CHeck this! Readable vs ReadableStream
expect(result).toBeInstanceOf(ReadableStream);
});

it('should be able to actually retrieve object as stream', async () => {
const bucket = await S3Bucket.getOrCreateBucket(
generateRandomBucketName(),
Expand All @@ -159,9 +147,7 @@ describe('getOrCreateBucket', () => {
throw new Error('result is undefined');
}

//Read the stream and compare the result to the original buffer
const readResult = await result.getReader().read();
expect(readResult.value).toEqual(data);
expect(await result.transformToByteArray()).toEqual(data);
});

it('should be able to handle missing key exception', async () => {
Expand Down

0 comments on commit 6606b19

Please sign in to comment.