Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/lib/storage/drivers/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class Local implements StorageDriver {
return false;
}

getStream(filePath: string): ReadStream {
getAsStream(filePath: string): ReadStream {
return createReadStream(join(this.config.basePath || '', filePath));
}

Expand Down
21 changes: 19 additions & 2 deletions packages/core/lib/storage/drivers/s3Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,25 @@ export class S3Storage implements StorageDriver {
this.initialiseModules();
}

getStream(filePath: string): ReadStream {
throw new Error('Method not implemented.');
getAsStream(filePath: string): ReadStream {
this.initialiseModules();

try {
const command = new this.AWS.GetObjectCommand({
Bucket: this.config.bucket,
Key: this.getPath(filePath),
});

const response = this.client.send(command);
return response.Body as ReadStream;
} catch (error) {
if (this.shouldThrowError()) {
throw new CannotPerformFileOpException(
`Cannot get stream for file ${filePath}: ${error['message']}`,
);
}
return null;
}
}

listDir(path: string): Promise<Record<string, any>> {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/lib/storage/interfaces/storageDriver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ReadStream } from 'fs-extra';
import {
StorageDriver$GetFileResponse,
StorageDriver$FileMetadataResponse,
Expand Down Expand Up @@ -136,6 +137,11 @@ export interface StorageDriver {
*/
getAsJson(path: string, throwError: boolean): Promise<Record<string, any>>;

/**
* Read file as stream
*/
getAsStream(path: string): ReadStream;

temporaryUrl(
path: string,
ttlInMins: number,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@intentjs/core",
"version": "0.1.60",
"version": "0.1.61",
"description": "Core module for Intent",
"repository": {
"type": "git",
Expand Down
Loading