Skip to content

Instantly share code, notes, and snippets.

@filipeandre
Last active August 1, 2024 11:21
Show Gist options
  • Save filipeandre/4a92758762eb00b76fecc34b455484af to your computer and use it in GitHub Desktop.
Save filipeandre/4a92758762eb00b76fecc34b455484af to your computer and use it in GitHub Desktop.
Get a gziped file from s3 to memory
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