Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GetObject example to use new transform util. #3876

Merged
merged 1 commit into from
Oct 28, 2022
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 javascriptv3/example_code/s3/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "Apache 2.0",
"transform": {},
"dependencies": {
"@aws-sdk/client-s3": "^3.32.0",
"@aws-sdk/client-s3": "^3.196.0",
"@aws-sdk/node-http-handler": "^3.32.0"
},
"scripts": {
Expand Down
17 changes: 3 additions & 14 deletions javascriptv3/example_code/s3/src/s3_getobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Inputs (replace in code):
- KEY

Running the code:
nodes3_getobject.js
node s3_getobject.js

[Outputs | Returns]:
Returns the object} from the Amazon S3 bucket.
Expand All @@ -30,26 +30,15 @@ export const bucketParams = {

export const run = async () => {
try {
// Create a helper function to convert a ReadableStream to a string.
const streamToString = (stream) =>
new Promise((resolve, reject) => {
const chunks = [];
stream.on("data", (chunk) => chunks.push(chunk));
stream.on("error", reject);
stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
});

// Get the object} from the Amazon S3 bucket. It is returned as a ReadableStream.
const data = await s3Client.send(new GetObjectCommand(bucketParams));
return data; // For unit tests.
// Convert the ReadableStream to a string.
const bodyContents = await streamToString(data.Body);
console.log(bodyContents);
return bodyContents;
return await data.Body.transformToString();
} catch (err) {
console.log("Error", err);
}
};

run();
// snippet-end:[s3.JavaScript.buckets.getobjectV3]
// For unit testing only.
Expand Down
15 changes: 0 additions & 15 deletions javascriptv3/example_code/s3/tests/s3_getobject.test.js

This file was deleted.