Replies: 3 comments
-
Are you missing the import or require from in the above code snippet?
|
Beta Was this translation helpful? Give feedback.
0 replies
-
yep. i have do it. its complete code block. const { Readable } = require("node:stream");
const { createReadStream } = require("node:fs");
const { buffer: arrayBuffer } = require("node:stream/consumers");
const { resolve } = require("node:path");
const { TransformStream, ReadableStream } = require("node:stream/web");
const tfs = new TransformStream(
{
transform(chunk, controller) {
controller.enqueue(chunk + ".");
},
},
{
highWaterMark: 5,
},
{
highWaterMark: 5,
},
);
(async () => {
const writer = tfs.writable.getWriter();
const readableStream = tfs.readable;
await writer.write(1);
await writer.write(2);
await writer.write(3);
// Transform cloud be read. ✅
// const reader = tfs.readable.getReader();
// console.log(await reader.read());
// console.log(await reader.read());
// console.log(await reader.read());
// reader.releaseLock();
// ❌ cannot be consumers(did not work)
const streamReadable = Readable.from(readableStream);
// streamReadable.on("data", (chunk) => {
// console.log("chunk", chunk);
// });
console.log("readable", streamReadable instanceof Readable); // readable true
const dataAsync = arrayBuffer(streamReadable);
console.log("check", dataAsync);
const data = await dataAsync; // BAD
console.log("from readable: ", data);
// Stream.readable ✅
// const fileReadable = createReadStream(resolve(__dirname, "assets/test.txt"));
// const dataAsync = arrayBuffer(fileReadable);
// console.log("check", dataAsync);
// const data = await dataAsync;
// console.log("from readable: ", data);
})(); |
Beta Was this translation helpful? Give feedback.
0 replies
-
Sounds like a question more than a bug report? I'll convert this to a discussion. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Version
v18.12.0
Platform
macos monterey 12.2.1(Darwin arm64)
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
No response
What do you see instead?
Additional information
This is not the only web strem tool, but most of the tools in the node documentation are basically like this
doc: https://nodejs.org/dist/latest-v18.x/docs/api/webstreams.html#class-compressionstream
Beta Was this translation helpful? Give feedback.
All reactions