🪣 RXJS operators for working with AWS S3
npm i @rxtk/s3
yarn add @rxtk/s3
Downloads a file to AWS S3 (as a stream).
import AWS from 'aws-sdk';
import {concat} from 'rxjs';
import {fromS3file} from '@rxtk/s3';
// Download AWS S3 file as a stream of file chunks (Buffers)
const downloadParams = {
s3Bucket: 'my-fabulous-bucket',
s3Key: 'path/to/file/hello-world.json',
byteLength: 32000, // (Optional) Size of the download chunks. Defaults to 32000.
s3Client: new AWS.S3(), // (Optional) The s3 client to use
rawResponse: false, // (Optional) - expose raw S3 JSON responses. Defaults to false.
};
const bufferChunk$ = fromS3File(downloadParams);
bufferchunk$.subscribe(console.log);
Uploads a file to AWS S3 (as a stream).
import {concat} from 'rxjs';
import {toS3File} from '@rxtk/s3';
// create a stream of file chunks
const chunk0 = Buffer.from('{"hello":');
const chunk1 = Buffer.from('"world"}');
const chunk$ = concat(chunk0, chunk1);
// upload the chunks to an AWS S3 file
const uploadParams = {
s3Bucket: 'my-fabulous-bucket',
s3Key: 'path/to/file/hello-world.json',
contentType: 'application/json',
};
const upload$ = chunk$.pipe(toS3File(uploadParams));
upload$.subscribe(console.log);