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

fix(hash-stream-node): do not create copy of file stream #3380

Merged
merged 1 commit into from
Mar 1, 2022

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Feb 28, 2022

Issue

Fixes: #3378

Description

Do not create a copy of file stream.

Testing

Integration testing

Verified that following operations are successful:

PutObject file without checksum
import { S3 } from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";
import { createReadStream } from "fs";

const region = "us-west-2";
const client = new S3({ region });

// File created with command "(for i in {1..1000}; do echo $i "hello world"; done) > hello-world.txt"
const fileName = "hello-world.txt";
const readableStream = createReadStream(fileName);

const Bucket = "aws-sdk-js-trivikr";
const Key = fileName;
const Body = readableStream;

await client.putObject({ Bucket, Key, Body });
PutObject file with checksum
import { S3 } from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";
import { createReadStream } from "fs";

const region = "us-west-2";
const client = new S3({ region });

// File created with command "(for i in {1..1000}; do echo $i "hello world"; done) > hello-world.txt"
const fileName = "hello-world.txt";
const readableStream = createReadStream(fileName);

const Bucket = "aws-sdk-js-trivikr";
const Key = fileName;
const Body = readableStream;
const ChecksumAlgorithm = "CRC32";

await client.putObject({ Bucket, Key, Body, ChecksumAlgorithm });
GetObject file with checksum
import { S3 } from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";
import { createWriteStream } from "fs";

const region = "us-west-2";
const client = new S3({ region });

const fileName = "hello-world.txt";
const Bucket = "aws-sdk-js-trivikr-flexible-checksums-testing";
const Key = fileName;
const ChecksumMode = "ENABLED";

const { Body } = await client.getObject({ Bucket, Key, ChecksumMode });
const writeStream = createWriteStream("./hello-world-copy.txt");
Body.pipe(writeStream);

Diff is empty:

$ diff hello-world.txt hello-world-copy.txt

Additional context

The issue with fd.createReadStream will be tracked in #3377


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr merged commit 89a70ae into aws:main Mar 1, 2022
@trivikr trivikr deleted the hash-stream-do-not-copy-file-stream branch March 1, 2022 18:13
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants