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

Function _duplexify

lib/internal/streams/duplexify.js:258–389  ·  view source on GitHub ↗
(pair)

Source from the content-addressed store, hash-verified

256}
257
258function _duplexify(pair) {
259 const r = pair.readable && typeof pair.readable.read !== 'function' ?
260 Readable.wrap(pair.readable) : pair.readable;
261 const w = pair.writable;
262
263 let readable = !!isReadable(r);
264 let writable = !!isWritable(w);
265
266 let ondrain;
267 let onfinish;
268 let onreadable;
269 let onclose;
270 let d;
271
272 function onfinished(err) {
273 const cb = onclose;
274 onclose = null;
275
276 if (cb) {
277 cb(err);
278 } else if (err) {
279 d.destroy(err);
280 }
281 }
282
283 // TODO(ronag): Avoid double buffering.
284 // Implement Writable/Readable/Duplex traits.
285 // See, https://github.com/nodejs/node/pull/33515.
286 d = new Duplexify({
287 // TODO (ronag): highWaterMark?
288 readableObjectMode: !!r?.readableObjectMode,
289 writableObjectMode: !!w?.writableObjectMode,
290 readable,
291 writable,
292 });
293
294 if (writable) {
295 eos(w, (err) => {
296 writable = false;
297 if (err) {
298 destroyer(r, err);
299 }
300 onfinished(err);
301 });
302
303 d._write = function(chunk, encoding, callback) {
304 if (w.write(chunk, encoding)) {
305 callback();
306 } else {
307 ondrain = callback;
308 }
309 };
310
311 d._final = function(callback) {
312 w.end();
313 onfinish = callback;
314 };
315

Callers 1

duplexify.jsFile · 0.85

Calls 13

isReadableFunction · 0.85
eosFunction · 0.85
isWritableFunction · 0.70
destroyerFunction · 0.70
onfinishedFunction · 0.70
cbFunction · 0.70
callbackFunction · 0.50
wrapMethod · 0.45
writeMethod · 0.45
endMethod · 0.45
onMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…