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(util-body-length-node): support fd.createReadStream #3385

Merged
merged 5 commits into from
Mar 8, 2022

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Feb 28, 2022

Issue

Fixes: #3377

Description

Compute length when fs.ReadStream is created using fd.createReadStream

Testing

Verified that object is successfully put in the following cases:

PutObject without Checksum
import { S3 } from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";
import { open } from "fs/promises";

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 fd = await open(fileName);
const readableStream = fd.createReadStream();

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

try {
  await client.putObject({ Bucket, Key, Body });
} catch (error) {
  console.log({ error });
}
PutObject with Checksum
import { S3 } from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";
import { open } from "fs/promises";

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 fd = await open(fileName);
const readableStream = fd.createReadStream();

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

try {
  await client.putObject({ Bucket, Key, Body, ChecksumAlgorithm });
} catch (error) {
  console.log({ error });
}

Additional context

This PR will be rebased after #3384 is merged. Ready!


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 force-pushed the fix-util-body-length-node-fd branch from 3cfd63e to 6a7483f Compare March 8, 2022 20:45
@trivikr trivikr marked this pull request as ready for review March 8, 2022 20:49
@trivikr trivikr requested a review from a team as a code owner March 8, 2022 20:49
@trivikr trivikr merged commit 88f8cc2 into aws:main Mar 8, 2022
@trivikr trivikr deleted the fix-util-body-length-node-fd branch March 8, 2022 21:32
@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 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S3 throws NotImplemented error if readStream is created from a file descriptor
3 participants