Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4422203
test_stream_transform_async_callback.cjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
804 B
Referenced Files
None
Subscribers
None
test_stream_transform_async_callback.cjs
View Options
const { Transform } = require('node:stream');
async function main() {
let output = '';
const tr = new Transform({
transform(chunk, encoding, cb) {
Promise.resolve().then(() => {
cb(null, chunk.toString('utf8').toUpperCase());
});
},
});
tr.on('data', (chunk) => {
output += chunk.toString('utf8');
});
const finished = new Promise((resolve, reject) => {
tr.on('finish', resolve);
tr.on('error', reject);
});
tr.write('abc');
tr.end();
await finished;
if (output !== 'ABC') {
throw new Error(`expected "ABC", got ${JSON.stringify(output)}`);
}
console.log('stream Transform async callback preserves receiver state');
}
main().catch((err) => {
console.error(err && err.stack ? err.stack : String(err));
process.exit(1);
});
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Sat, May 2, 1:06 AM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
542972
Default Alt Text
test_stream_transform_async_callback.cjs (804 B)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment