Created
February 28, 2026 03:30
-
-
Save forivall/528991d94dc9315fa6683b3c2402daee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {import('stream').Transform} stream | |
| * @param {string} data | |
| */ | |
| function transformSync(stream, data) { | |
| if (data.length > stream.writableHighWaterMark) { | |
| throw new Error('Data is too large for synchronous transform'); | |
| } | |
| let done = false; | |
| stream.write(data, (err) => { | |
| if (err) { | |
| throw err; | |
| } else { | |
| done = true; | |
| } | |
| }); | |
| /** @type Array<string | object> */ | |
| const results = []; | |
| stream.on('data', (chunk) => results.push(chunk)); | |
| if (!done) { | |
| throw new Error('Stream did not flush after write'); | |
| } | |
| return results; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment