* @param {ReadableWritablePair} pair * @param {{ * allowHalfOpen? : boolean, * decodeStrings? : boolean, * encoding? : string, * highWaterMark? : number, * objectMode? : boolean, * signal? : AbortSignal, * }} [options] * @returns {Duplex}
(pair = kEmptyObject, options = kEmptyObject)
| 740 | * @returns {Duplex} |
| 741 | */ |
| 742 | function newStreamDuplexFromReadableWritablePair(pair = kEmptyObject, options = kEmptyObject) { |
| 743 | validateObject(pair, 'pair'); |
| 744 | const { |
| 745 | readable: readableStream, |
| 746 | writable: writableStream, |
| 747 | } = pair; |
| 748 | |
| 749 | if (!isReadableStream(readableStream)) { |
| 750 | throw new ERR_INVALID_ARG_TYPE( |
| 751 | 'pair.readable', |
| 752 | 'ReadableStream', |
| 753 | readableStream); |
| 754 | } |
| 755 | if (!isWritableStream(writableStream)) { |
| 756 | throw new ERR_INVALID_ARG_TYPE( |
| 757 | 'pair.writable', |
| 758 | 'WritableStream', |
| 759 | writableStream); |
| 760 | } |
| 761 | |
| 762 | validateObject(options, 'options'); |
| 763 | const { |
| 764 | allowHalfOpen = false, |
| 765 | objectMode = false, |
| 766 | encoding, |
| 767 | decodeStrings = true, |
| 768 | highWaterMark, |
| 769 | signal, |
| 770 | } = options; |
| 771 | |
| 772 | validateBoolean(objectMode, 'options.objectMode'); |
| 773 | if (encoding !== undefined && !Buffer.isEncoding(encoding)) |
| 774 | throw new ERR_INVALID_ARG_VALUE('options.encoding', encoding); |
| 775 | |
| 776 | const writer = writableStream.getWriter(); |
| 777 | const reader = readableStream.getReader(); |
| 778 | let writableClosed = false; |
| 779 | let readableClosed = false; |
| 780 | |
| 781 | const duplex = new Duplex({ |
| 782 | allowHalfOpen, |
| 783 | highWaterMark, |
| 784 | objectMode, |
| 785 | encoding, |
| 786 | decodeStrings, |
| 787 | signal, |
| 788 | |
| 789 | writev(chunks, callback) { |
| 790 | function done(error) { |
| 791 | try { |
| 792 | callback(error); |
| 793 | } catch (error) { |
| 794 | // In a next tick because this is happening within |
| 795 | // a promise context, and if there are any errors |
| 796 | // thrown we don't want those to cause an unhandled |
| 797 | // rejection. Let's just escape the promise and |
| 798 | // handle it separately. |
| 799 | process.nextTick(() => destroy(duplex, error)); |
no test coverage detected
searching dependent graphs…