Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created September 13, 2021 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaskills/399ec7564057e9221ac4723e93a6eecf to your computer and use it in GitHub Desktop.
Save metaskills/399ec7564057e9221ac4723e93a6eecf to your computer and use it in GitHub Desktop.
const { S3, GetObjectCommand } = require("@aws-sdk/client-s3");
const S3C = new S3(S3Config.mms());
response = await S3C.send(new GetObjectCommand(params));
data = await this.streamToString(response.Body);
async streamToString(stream) {
return new Promise((resolve, reject) => {
const chunks = [];
stream.on("data", (chunk) => chunks.push(chunk));
stream.on("error", reject);
stream.on("end", () => resolve(Buffer.concat(chunks)));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment