Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Why is process stdin/stdout/stderr a stream.Duplex? #7941

Closed
killmag10 opened this issue Jul 13, 2014 · 3 comments
Closed

Why is process stdin/stdout/stderr a stream.Duplex? #7941

killmag10 opened this issue Jul 13, 2014 · 3 comments

Comments

@killmag10
Copy link

Hi,

why is process stdin/stdout/stderr a stream.Duplex?

On the doc's stdin is a stream.Readable and stdout/stderr is a stream.Writable.

Tested on 0.10.29:

$ node
> process.stdin instanceof require('stream').Readable;
true
> process.stdin instanceof require('stream').Writable;
false
> process.stdin instanceof require('stream').Duplex;
true
> process.stdout instanceof require('stream').Readable;
true
> process.stdout instanceof require('stream').Writable;
false
> process.stdout instanceof require('stream').Duplex;
true
> process.stderr instanceof require('stream').Readable;
true
> process.stderr instanceof require('stream').Writable;
false
> process.stderr instanceof require('stream').Duplex;
true

Is this correct?

@chrisdickinson
Copy link

std{in,out,err} all inherit from net.Socket, which is a stream.Duplex. For all intents and purposes, stdin should be thought of as a Readable, and std{out,err} as Writable's.

@TooTallNate
Copy link

What @chrisdickinson said: it's an implementation detail. Don't rely on it.

For example, if you redirect stdout to a file, then it will be a fs.WriteStream instance instead of a net.Socket.

@killmag10
Copy link
Author

OK, thank for your response. :)

I write a nodejs compatibility layer for java, so i'm interested on implementation details. ;)

kaiquewdev pushed a commit to kaiquewdev/node that referenced this issue Nov 26, 2016
Notable Changes:

* Buffer
  * Passing invalid input to Buffer.byteLength will now throw an error [nodejs#8946](nodejs/node#8946).
  * Calling Buffer without new is now deprecated and will emit a process warning [nodejs#8169](nodejs/node#8169).
  * Passing a negative number to allocUnsafe will now throw an error [nodejs#7079](nodejs/node#7079).
* Child Process
  * The fork and execFile methods now have stronger argument validation [nodejs#7399](nodejs/node#7399).
* Cluster
  * The worker.suicide method is deprecated and will emit a process warning [nodejs#3747](nodejs/node#3747).
* Deps
  * V8 has been updated to 5.4.500.36 [nodejs#8317](nodejs/node#8317), [nodejs#8852](nodejs/node#8852), [nodejs#9253](nodejs/node#9253).
  * NODE_MODULE_VERSION has been updated to 51 [nodejs#8808](nodejs/node#8808).
* File System
  * A process warning is emitted if a callback is not passed to async file system methods [nodejs#7897](nodejs/node#7897).
* Intl
  * Intl.v8BreakIterator constructor has been deprecated and will emit a process warning [nodejs#8908](nodejs/node#8908).
* Promises
  * Unhandled Promise rejections have been deprecated and will emit a process warning [nodejs#8217](nodejs/node#8217).
* Punycode
  * The `punycode` module has been deprecated [nodejs#7941](nodejs/node#7941).
* URL
  * An Experimental WHATWG URL Parser has been introduced [nodejs#7448](nodejs/node#7448).

PR-URL: nodejs/node#9099
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants