MCPcopy Index your code
hub / github.com/nodejs/node / newStreamWritableFromWritableStream

Function newStreamWritableFromWritableStream

lib/internal/webstreams/adapters.js:295–457  ·  view source on GitHub ↗

* @param {WritableStream} writableStream * @param {{ * decodeStrings? : boolean, * highWaterMark? : number, * objectMode? : boolean, * signal? : AbortSignal, * }} [options] * @returns {Writable}

(writableStream, options = kEmptyObject)

Source from the content-addressed store, hash-verified

293 * @returns {Writable}
294 */
295function newStreamWritableFromWritableStream(writableStream, options = kEmptyObject) {
296 if (!isWritableStream(writableStream)) {
297 throw new ERR_INVALID_ARG_TYPE(
298 'writableStream',
299 'WritableStream',
300 writableStream);
301 }
302
303 validateObject(options, 'options');
304 const {
305 highWaterMark,
306 decodeStrings = true,
307 objectMode = false,
308 signal,
309 } = options;
310
311 validateBoolean(objectMode, 'options.objectMode');
312 validateBoolean(decodeStrings, 'options.decodeStrings');
313
314 const writer = writableStream.getWriter();
315 let closed = false;
316
317 const writable = new Writable({
318 highWaterMark,
319 objectMode,
320 decodeStrings,
321 signal,
322
323 writev(chunks, callback) {
324 function done(error) {
325 try {
326 callback(error);
327 } catch (error) {
328 // In a next tick because this is happening within
329 // a promise context, and if there are any errors
330 // thrown we don't want those to cause an unhandled
331 // rejection. Let's just escape the promise and
332 // handle it separately.
333 process.nextTick(() => destroy(writable, error));
334 }
335 }
336
337 PromisePrototypeThen(
338 writer.ready,
339 () => {
340 return PromisePrototypeThen(
341 SafePromiseAllReturnVoid(
342 chunks,
343 (data) => writer.write(data.chunk)),
344 done,
345 done);
346 },
347 done);
348 },
349
350 write(chunk, encoding, callback) {
351 if (typeof chunk === 'string' && decodeStrings && !objectMode) {
352 const enc = normalizeEncoding(encoding);

Calls 4

isWritableStreamFunction · 0.85
isWritableEndedFunction · 0.85
getWriterMethod · 0.80
destroyFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…