Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 27x 27x 27x 27x 27x 11x 11x 11x 11x 27x 27x 8x 8x 8x 8x 8x 27x 3x 3x 3x 30x 1x 1x 29x 30x 2x 2x 27x 30x 2x 2x 25x 30x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 30x 14x 14x 14x 6x 6x 6x 6x 6x 6x 6x 6x 8x 14x 14x 7x 7x 7x 7x 7x 7x 6x 1x 1x 7x 7x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 6x 6x 6x 5x 6x 1x 1x 6x 7x 7x 7x 7x 1x 1x 1x 1x 11x 30x 1x 1x 10x 19x 1x 1x 1x 1x 1x 1x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 30x 5x 30x 6x 4x 6x 6x 6x 6x 4x 6x 6x 6x 6x 6x 3x 30x 30x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 3x 3x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 14x 14x 14x 14x 14x 14x 38x 38x 38x 38x 38x 26x 38x 26x 26x 26x 14x 14x 14x 14x 14x 26x 26x 26x 14x 14x 12x 12x 12x 14x 14x 7x 7x 7x 14x 14x 3x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 5x 5x 2x 5x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 6x 4x 4x 1x 1x 4x 6x 6x 6x 6x 5x 6x 1x 1x 6x 6x 6x 4x 4x 6x 6x 6x 6x 6x 6x 3x 3x 3x 3x 3x 6x 6x 10x 10x 6x 6x 6x 1x 1x 6x 6x 6x 6x 5x 5x 5x 5x 5x 6x 6x 6x 5x 6x 6x 6x 12x 17x 17x 17x 12x 12x 12x 5x 17x 17x 6x 6x 10x 10x 8x 5x 5x 8x 8x 8x 8x 8x 8x 3x 8x 5x 5x 5x 5x 10x 10x 10x 10x | 'use strict'; const { isReadable, isWritable, isIterable, isNodeStream, isReadableNodeStream, isWritableNodeStream, isDuplexNodeStream, } = require('internal/streams/utils'); const eos = require('internal/streams/end-of-stream'); const { AbortError, codes: { ERR_INVALID_ARG_TYPE, ERR_INVALID_RETURN_VALUE, }, } = require('internal/errors'); const { destroyer } = require('internal/streams/destroy'); const Duplex = require('internal/streams/duplex'); const Readable = require('internal/streams/readable'); const { createDeferredPromise } = require('internal/util'); const from = require('internal/streams/from'); const { isBlob, } = require('internal/blob'); const { AbortController } = require('internal/abort_controller'); const { FunctionPrototypeCall } = primordials; // This is needed for pre node 17. class Duplexify extends Duplex { constructor(options) { super(options); // https://github.com/nodejs/node/pull/34385 if (options?.readable === false) { this._readableState.readable = false; this._readableState.ended = true; this._readableState.endEmitted = true; } if (options?.writable === false) { this._writableState.writable = false; this._writableState.ending = true; this._writableState.ended = true; this._writableState.finished = true; } } } module.exports = function duplexify(body, name) { if (isDuplexNodeStream(body)) { return body; } if (isReadableNodeStream(body)) { return _duplexify({ readable: body }); } if (isWritableNodeStream(body)) { return _duplexify({ writable: body }); } if (isNodeStream(body)) { return _duplexify({ writable: false, readable: false }); } // TODO: Webstreams // if (isReadableStream(body)) { // return _duplexify({ readable: Readable.fromWeb(body) }); // } // TODO: Webstreams // if (isWritableStream(body)) { // return _duplexify({ writable: Writable.fromWeb(body) }); // } if (typeof body === 'function') { const { value, write, final, destroy } = fromAsyncGen(body); if (isIterable(value)) { return from(Duplexify, value, { // TODO (ronag): highWaterMark? objectMode: true, write, final, destroy }); } const then = value?.then; if (typeof then === 'function') { let d; const promise = FunctionPrototypeCall( then, value, (val) => { if (val != null) { throw new ERR_INVALID_RETURN_VALUE('nully', 'body', val); } }, (err) => { destroyer(d, err); } ); return d = new Duplexify({ // TODO (ronag): highWaterMark? objectMode: true, readable: false, write, final(cb) { final(async () => { try { await promise; process.nextTick(cb, null); } catch (err) { process.nextTick(cb, err); } }); }, destroy }); } throw new ERR_INVALID_RETURN_VALUE( 'Iterable, AsyncIterable or AsyncFunction', name, value); } if (isBlob(body)) { return duplexify(body.arrayBuffer()); } if (isIterable(body)) { return from(Duplexify, body, { // TODO (ronag): highWaterMark? objectMode: true, writable: false }); } // TODO: Webstreams. // if ( // isReadableStream(body?.readable) && // isWritableStream(body?.writable) // ) { // return Duplexify.fromWeb(body); // } if ( typeof body?.writable === 'object' || typeof body?.readable === 'object' ) { const readable = body?.readable ? isReadableNodeStream(body?.readable) ? body?.readable : duplexify(body.readable) : undefined; const writable = body?.writable ? isWritableNodeStream(body?.writable) ? body?.writable : duplexify(body.writable) : undefined; return _duplexify({ readable, writable }); } const then = body?.then; if (typeof then === 'function') { let d; FunctionPrototypeCall( then, body, (val) => { if (val != null) { d.push(val); } d.push(null); }, (err) => { destroyer(d, err); } ); return d = new Duplexify({ objectMode: true, writable: false, read() {} }); } throw new ERR_INVALID_ARG_TYPE( name, ['Blob', 'ReadableStream', 'WritableStream', 'Stream', 'Iterable', 'AsyncIterable', 'Function', '{ readable, writable } pair', 'Promise'], body); }; function fromAsyncGen(fn) { let { promise, resolve } = createDeferredPromise(); const ac = new AbortController(); const signal = ac.signal; const value = fn(async function*() { while (true) { const _promise = promise; promise = null; const { chunk, done, cb } = await _promise; process.nextTick(cb); if (done) return; if (signal.aborted) throw new AbortError(undefined, { cause: signal.reason }); ({ promise, resolve } = createDeferredPromise()); yield chunk; } }(), { signal }); return { value, write(chunk, encoding, cb) { const _resolve = resolve; resolve = null; _resolve({ chunk, done: false, cb }); }, final(cb) { const _resolve = resolve; resolve = null; _resolve({ done: true, cb }); }, destroy(err, cb) { ac.abort(); cb(err); } }; } function _duplexify(pair) { const r = pair.readable && typeof pair.readable.read !== 'function' ? Readable.wrap(pair.readable) : pair.readable; const w = pair.writable; let readable = !!isReadable(r); let writable = !!isWritable(w); let ondrain; let onfinish; let onreadable; let onclose; let d; function onfinished(err) { const cb = onclose; onclose = null; if (cb) { cb(err); } else if (err) { d.destroy(err); } else if (!readable && !writable) { d.destroy(); } } // TODO(ronag): Avoid double buffering. // Implement Writable/Readable/Duplex traits. // See, https://github.com/nodejs/node/pull/33515. d = new Duplexify({ // TODO (ronag): highWaterMark? readableObjectMode: !!r?.readableObjectMode, writableObjectMode: !!w?.writableObjectMode, readable, writable, }); if (writable) { eos(w, (err) => { writable = false; if (err) { destroyer(r, err); } onfinished(err); }); d._write = function(chunk, encoding, callback) { if (w.write(chunk, encoding)) { callback(); } else { ondrain = callback; } }; d._final = function(callback) { w.end(); onfinish = callback; }; w.on('drain', function() { if (ondrain) { const cb = ondrain; ondrain = null; cb(); } }); w.on('finish', function() { if (onfinish) { const cb = onfinish; onfinish = null; cb(); } }); } if (readable) { eos(r, (err) => { readable = false; if (err) { destroyer(r, err); } onfinished(err); }); r.on('readable', function() { if (onreadable) { const cb = onreadable; onreadable = null; cb(); } }); r.on('end', function() { d.push(null); }); d._read = function() { while (true) { const buf = r.read(); if (buf === null) { onreadable = d._read; return; } if (!d.push(buf)) { return; } } }; } d._destroy = function(err, callback) { if (!err && onclose !== null) { err = new AbortError(); } onreadable = null; ondrain = null; onfinish = null; if (onclose === null) { callback(err); } else { onclose = callback; destroyer(w, err); destroyer(r, err); } }; return d; } |