Last active
August 1, 2024 11:21
-
-
Save filipeandre/4a92758762eb00b76fecc34b455484af to your computer and use it in GitHub Desktop.
Get a gziped file from s3 to memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createGunzip } from 'node:zlib'; | |
| import { text } from 'node:stream/consumers'; | |
| import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3'; | |
| async function readGzippedFromS3(s3Client: S3Client, bucket: string, objectKey: string): Promise<string> { | |
| const command = new GetObjectCommand({ | |
| Bucket: bucket, | |
| Key: objectKey, | |
| }); | |
| const response = await s3Client.send(command); | |
| const gunzip = createGunzip(); | |
| const body = response.Body.pipe(gunzip); | |
| return text(body); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment