File tree 2 files changed +100
-0
lines changed
2 files changed +100
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const pipeline = require ( 'internal/streams/pipeline' ) ;
4
+ const Duplex = require ( 'internal/streams/duplex' ) ;
5
+ const { destroyer } = require ( 'internal/streams/destroy' ) ;
6
+
7
+ module . exports = function pipe ( ...streams ) {
8
+ let onclose ;
9
+ let ret ;
10
+
11
+ const r = pipeline ( streams , function ( err ) {
12
+ if ( onclose ) {
13
+ const cb = onclose ;
14
+ onclose = null ;
15
+ cb ( err ) ;
16
+ } else {
17
+ ret . destroy ( err ) ;
18
+ }
19
+ } ) ;
20
+ const w = streams [ 0 ] ;
21
+
22
+ const writable = w . writable ;
23
+ const readable = r . readable ;
24
+ const objectMode = w . readableObjectMode ;
25
+
26
+ ret = new Duplex ( {
27
+ writable,
28
+ readable,
29
+ objectMode,
30
+ highWaterMark : 1
31
+ } ) ;
32
+
33
+ if ( writable ) {
34
+ let ondrain ;
35
+ let onfinish ;
36
+
37
+ ret . _write = function ( chunk , encoding , callback ) {
38
+ if ( w . write ( chunk , encoding ) ) {
39
+ callback ( ) ;
40
+ } else {
41
+ ondrain = callback ;
42
+ }
43
+ } ;
44
+
45
+ ret . _final = function ( chunk , encoding , callback ) {
46
+ w . end ( chunk , encoding ) ;
47
+ onfinish = callback ;
48
+ } ;
49
+
50
+ ret . on ( 'drain' , function ( ) {
51
+ if ( ondrain ) {
52
+ const cb = ondrain ;
53
+ ondrain = null ;
54
+ cb ( ) ;
55
+ }
56
+ } ) ;
57
+
58
+ ret . on ( 'finish' , function ( ) {
59
+ if ( onfinish ) {
60
+ const cb = onfinish
61
+ onfinish = null ;
62
+ cb ( ) ;
63
+ }
64
+ } ) ;
65
+ }
66
+
67
+ if ( readable ) {
68
+ let onreadable ;
69
+
70
+ r . on ( 'readable' , function ( ) {
71
+ if ( onreadable ) {
72
+ const cb = onreadable
73
+ onreadable = null ;
74
+ cb ( ) ;
75
+ }
76
+ } ) ;
77
+
78
+ ret . _read = function ( ) {
79
+ while ( true ) {
80
+ const buf = r . read ( ) ;
81
+
82
+ if ( buf === null ) {
83
+ onreadable = ret . _read ;
84
+ return ;
85
+ }
86
+
87
+ if ( ! ret . push ( buf ) ) {
88
+ return ;
89
+ }
90
+ }
91
+ } ;
92
+ }
93
+
94
+ ret . _destroy = function ( err , callback ) {
95
+ onclose = callback ;
96
+ r . destroy ( err ) ;
97
+ } ;
98
+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ const {
30
30
} = require ( 'internal/util' ) ;
31
31
32
32
const pipeline = require ( 'internal/streams/pipeline' ) ;
33
+ const pipelinify = require ( 'internal/streams/pipelinify' ) ;
33
34
const eos = require ( 'internal/streams/end-of-stream' ) ;
34
35
const internalBuffer = require ( 'internal/buffer' ) ;
35
36
@@ -42,6 +43,7 @@ Stream.Duplex = require('internal/streams/duplex');
42
43
Stream . Transform = require ( 'internal/streams/transform' ) ;
43
44
Stream . PassThrough = require ( 'internal/streams/passthrough' ) ;
44
45
Stream . pipeline = pipeline ;
46
+ Stream . pipelinify = pipelinify ;
45
47
const { addAbortSignal } = require ( 'internal/streams/add-abort-signal' ) ;
46
48
Stream . addAbortSignal = addAbortSignal ;
47
49
Stream . finished = eos ;
You can’t perform that action at this time.
0 commit comments