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

chore(js-utils): switch from unenv to node-stdlib-browser #2071

Closed
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
5 changes: 2 additions & 3 deletions examples/javascript/s3-streamer/standalone_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Readable } from "node:stream";
import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
//import { Readable } from "node:stream";
import { Readable } from "/Users/nathan/rivet/ee/oss/packages/toolchain/js-utils-embed/js/node_modules/unenv/runtime/node/stream/index.mjs";

// Helper to convert Node streams to Web streams
function nodeStreamToWebStream(nodeStream: Readable) {
Expand Down Expand Up @@ -42,7 +41,7 @@ async function streamS3File(
// Convert S3 stream to Web stream
//console.log("Body type", response.Body?.constructor.name);
//const s3Stream = Readable.from(response.Body.transformToWebStream());
const webStream1 = response.Body.transformToWebStream();
const webStream1 = await response.Body.transformToByteArray();
console.log("Body type", webStream1.constructor.name);
const s3Stream = Readable.from(webStream1);
const webStream = nodeStreamToWebStream(s3Stream);
Comment on lines +44 to 47
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: transformToByteArray() loads entire response into memory at once, while transformToWebStream() streamed chunks. This could cause memory issues with large files.

Suggested change
const webStream1 = await response.Body.transformToByteArray();
console.log("Body type", webStream1.constructor.name);
const s3Stream = Readable.from(webStream1);
const webStream = nodeStreamToWebStream(s3Stream);
//const webStream1 = await response.Body.transformToByteArray();
//console.log("Body type", webStream1.constructor.name);
//const s3Stream = Readable.from(webStream1);
const webStream = nodeStreamToWebStream(Readable.from(response.Body.transformToWebStream()));

Expand Down
4 changes: 3 additions & 1 deletion packages/toolchain/js-utils-embed/js/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"consola": "npm:consola@^3.4.0",
"esbuild": "npm:[email protected]",
"glob": "npm:[email protected]",
"unenv": "npm:[email protected]",
"node-stdlib-browser": "npm:node-stdlib-browser@^1.3.1",
"pkg-dir": "npm:pkg-dir@^5.0.0",
"readable-stream": "npm:readable-stream@^4.7.0",
"zod": "npm:[email protected]",
"zod-validation-error": "npm:[email protected]"
}
Expand Down
Loading
Loading