Skip to content

Commit 9c62e0e

Browse files
mcollinanodejs-github-bot
authored andcommitted
stream: move to internal/streams
Move all the streams constructors to internal/streams and avoid a circular dependencies between the modules. See: nodejs/readable-stream#348 PR-URL: #35239 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
1 parent 039c274 commit 9c62e0e

15 files changed

+2606
-2575
lines changed

lib/_stream_duplex.js

+2-104
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,6 @@
1-
// Copyright Joyent, Inc. and other Node contributors.
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a
4-
// copy of this software and associated documentation files (the
5-
// "Software"), to deal in the Software without restriction, including
6-
// without limitation the rights to use, copy, modify, merge, publish,
7-
// distribute, sublicense, and/or sell copies of the Software, and to permit
8-
// persons to whom the Software is furnished to do so, subject to the
9-
// following conditions:
10-
//
11-
// The above copyright notice and this permission notice shall be included
12-
// in all copies or substantial portions of the Software.
13-
//
14-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21-
22-
// a duplex stream is just a stream that is both readable and writable.
23-
// Since JS doesn't have multiple prototype inheritance, this class
24-
// prototypically inherits from Readable, and then parasitically from
25-
// Writable.
26-
271
'use strict';
282

29-
const {
30-
ObjectDefineProperties,
31-
ObjectGetOwnPropertyDescriptor,
32-
ObjectKeys,
33-
ObjectSetPrototypeOf,
34-
} = primordials;
3+
// TODO(mcollina): deprecate this file
354

5+
const Duplex = require('internal/streams/duplex');
366
module.exports = Duplex;
37-
38-
const Readable = require('_stream_readable');
39-
const Writable = require('_stream_writable');
40-
41-
ObjectSetPrototypeOf(Duplex.prototype, Readable.prototype);
42-
ObjectSetPrototypeOf(Duplex, Readable);
43-
44-
{
45-
// Allow the keys array to be GC'ed.
46-
for (const method of ObjectKeys(Writable.prototype)) {
47-
if (!Duplex.prototype[method])
48-
Duplex.prototype[method] = Writable.prototype[method];
49-
}
50-
}
51-
52-
function Duplex(options) {
53-
if (!(this instanceof Duplex))
54-
return new Duplex(options);
55-
56-
Readable.call(this, options);
57-
Writable.call(this, options);
58-
this.allowHalfOpen = true;
59-
60-
if (options) {
61-
if (options.readable === false)
62-
this.readable = false;
63-
64-
if (options.writable === false)
65-
this.writable = false;
66-
67-
if (options.allowHalfOpen === false) {
68-
this.allowHalfOpen = false;
69-
}
70-
}
71-
}
72-
73-
ObjectDefineProperties(Duplex.prototype, {
74-
writable:
75-
ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writable'),
76-
writableHighWaterMark:
77-
ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableHighWaterMark'),
78-
writableObjectMode:
79-
ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableObjectMode'),
80-
writableBuffer:
81-
ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableBuffer'),
82-
writableLength:
83-
ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableLength'),
84-
writableFinished:
85-
ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableFinished'),
86-
writableCorked:
87-
ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableCorked'),
88-
writableEnded:
89-
ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableEnded'),
90-
91-
destroyed: {
92-
get() {
93-
if (this._readableState === undefined ||
94-
this._writableState === undefined) {
95-
return false;
96-
}
97-
return this._readableState.destroyed && this._writableState.destroyed;
98-
},
99-
set(value) {
100-
// Backward compatibility, the user is explicitly
101-
// managing destroyed.
102-
if (this._readableState && this._writableState) {
103-
this._readableState.destroyed = value;
104-
this._writableState.destroyed = value;
105-
}
106-
}
107-
}
108-
});

lib/_stream_passthrough.js

+2-43
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,6 @@
1-
// Copyright Joyent, Inc. and other Node contributors.
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a
4-
// copy of this software and associated documentation files (the
5-
// "Software"), to deal in the Software without restriction, including
6-
// without limitation the rights to use, copy, modify, merge, publish,
7-
// distribute, sublicense, and/or sell copies of the Software, and to permit
8-
// persons to whom the Software is furnished to do so, subject to the
9-
// following conditions:
10-
//
11-
// The above copyright notice and this permission notice shall be included
12-
// in all copies or substantial portions of the Software.
13-
//
14-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21-
22-
// a passthrough stream.
23-
// basically just the most minimal sort of Transform stream.
24-
// Every written chunk gets output as-is.
25-
261
'use strict';
272

28-
const {
29-
ObjectSetPrototypeOf,
30-
} = primordials;
3+
// TODO(mcollina): deprecate this file
314

5+
const PassThrough = require('internal/streams/passthrough');
326
module.exports = PassThrough;
33-
34-
const Transform = require('_stream_transform');
35-
ObjectSetPrototypeOf(PassThrough.prototype, Transform.prototype);
36-
ObjectSetPrototypeOf(PassThrough, Transform);
37-
38-
function PassThrough(options) {
39-
if (!(this instanceof PassThrough))
40-
return new PassThrough(options);
41-
42-
Transform.call(this, options);
43-
}
44-
45-
PassThrough.prototype._transform = function(chunk, encoding, cb) {
46-
cb(null, chunk);
47-
};

0 commit comments

Comments
 (0)