Showing with 3,959 additions and 862 deletions.
  1. +1 −1 benchmark/net-pipe.js
  2. +42 −9 doc/api/crypto.markdown
  3. +63 −0 lib/_stream_duplex.js
  4. +18 −13 test/simple/test-zlib-destroy.js → lib/_stream_passthrough.js
  5. +774 −0 lib/_stream_readable.js
  6. +231 −0 lib/_stream_transform.js
  7. +254 −0 lib/_stream_writable.js
  8. +0 −3 lib/child_process.js
  9. +68 −11 lib/crypto.js
  10. +138 −270 lib/fs.js
  11. +88 −70 lib/http.js
  12. +253 −219 lib/net.js
  13. +2 −2 lib/repl.js
  14. +17 −4 lib/stream.js
  15. +7 −0 lib/string_decoder.js
  16. +20 −15 lib/tty.js
  17. +91 −124 lib/zlib.js
  18. +5 −0 node.gyp
  19. +14 −15 src/node.js
  20. +1 −1 src/node_version.h
  21. +13 −0 src/node_zlib.cc
  22. +2 −0 test/fixtures/echo.js
  23. +1 −0 test/fixtures/x1024.txt
  24. +2 −0 test/simple/test-child-process-disconnect.js
  25. +48 −10 test/simple/test-child-process-fork-net2.js
  26. +3 −0 test/simple/test-child-process-ipc.js
  27. +1 −0 test/simple/test-cluster-http-pipe.js
  28. +2 −0 test/simple/test-cluster-message.js
  29. +75 −2 test/simple/test-crypto.js
  30. +4 −8 test/simple/test-domain-http-server.js
  31. +20 −15 test/simple/test-file-write-stream.js
  32. +27 −13 test/simple/test-file-write-stream2.js
  33. +4 −2 test/simple/test-fs-empty-readStream.js
  34. +1 −3 test/simple/test-fs-read-stream.js
  35. +2 −1 test/simple/test-fs-write-stream-end.js
  36. +4 −0 test/simple/test-http-1.0-keep-alive.js
  37. +9 −1 test/simple/test-http-abort-client.js
  38. +7 −3 test/simple/test-http-agent.js
  39. +1 −0 test/simple/test-http-client-agent.js
  40. +3 −2 test/simple/test-http-client-pipe-end.js
  41. +5 −1 test/simple/test-http-connect.js
  42. +1 −0 test/simple/test-http-date-header.js
  43. +1 −0 test/simple/test-http-default-encoding.js
  44. +1 −0 test/simple/test-http-header-read.js
  45. +12 −9 test/simple/test-http-header-response-splitting.js
  46. +4 −2 test/simple/test-http-host-headers.js
  47. +5 −2 test/simple/test-http-keep-alive-close-on-header.js
  48. +3 −0 test/simple/test-http-keep-alive.js
  49. +1 −0 test/simple/test-http-many-keep-alive-connections.js
  50. +1 −0 test/simple/test-http-parser-free.js
  51. +1 −0 test/simple/test-http-request-end-twice.js
  52. +1 −0 test/simple/test-http-request-end.js
  53. +4 −2 test/simple/test-http-res-write-end-dont-take-array.js
  54. +1 −0 test/simple/test-http-response-readable.js
  55. +1 −0 test/simple/test-http-set-trailers.js
  56. +1 −0 test/simple/test-http-status-code.js
  57. +2 −0 test/simple/test-http-timeout.js
  58. +1 −0 test/simple/test-https-agent.js
  59. +2 −0 test/simple/test-https-socket-options.js
  60. +1 −0 test/simple/test-https-strict.js
  61. +2 −0 test/simple/test-net-after-close.js
  62. +23 −5 test/simple/test-net-binary.js
  63. +11 −4 test/simple/test-net-bytes-stats.js
  64. +2 −0 test/simple/test-net-can-reset-timeout.js
  65. +10 −3 test/simple/test-net-connect-buffer.js
  66. +4 −0 test/simple/test-net-connect-options.js
  67. +6 −3 test/simple/test-net-pingpong.js
  68. +14 −4 test/simple/test-net-reconnect.js
  69. +1 −0 test/simple/test-net-remote-address-port.js
  70. +4 −0 test/simple/test-net-write-after-close.js
  71. +13 −0 test/simple/test-pipe-file-to-http.js
  72. +1 −0 test/simple/test-pipe.js
  73. +1 −0 test/simple/test-regress-GH-877.js
  74. +2 −1 test/simple/test-repl-autolibs.js
  75. +320 −0 test/simple/test-stream2-basic.js
  76. +76 −0 test/simple/test-stream2-fs.js
  77. +105 −0 test/simple/test-stream2-pipe-error-handling.js
  78. +109 −0 test/simple/test-stream2-readable-from-list.js
  79. +299 −0 test/simple/test-stream2-set-encoding.js
  80. +314 −0 test/simple/test-stream2-transform.js
  81. +246 −0 test/simple/test-stream2-writable.js
  82. +1 −0 test/simple/test-tcp-wrap-connect.js
  83. +13 −2 test/simple/test-tls-pause.js
  84. +0 −7 test/simple/test-zlib-invalid-input.js
  85. +17 −0 test/simple/test-zlib-random-byte-pipes.js
@@ -27,7 +27,7 @@ Writer.prototype.write = function(chunk, encoding, cb) {

// doesn't matter, never emits anything.
Writer.prototype.on = function() {};

Writer.prototype.once = function() {};
Writer.prototype.emit = function() {};

var statCounter = 0;
@@ -89,6 +89,11 @@ Example: this program that takes the sha1 sum of a file

The class for creating hash digests of data.

It is a [stream](stream.html) that is both readable and writable. The
written data is used to compute the hash. Once the writable side of
the stream is ended, use the `read()` method to get the computed hash
digest. The legacy `update` and `digest` methods are also supported.

Returned by `crypto.createHash`.

### hash.update(data, [input_encoding])
@@ -114,6 +119,11 @@ called.
Creates and returns a hmac object, a cryptographic hmac with the given
algorithm and key.

It is a [stream](stream.html) that is both readable and writable. The
written data is used to compute the hmac. Once the writable side of
the stream is ended, use the `read()` method to get the computed
digest. The legacy `update` and `digest` methods are also supported.

`algorithm` is dependent on the available algorithms supported by
OpenSSL - see createHash above. `key` is the hmac key to be used.

@@ -148,6 +158,11 @@ recent releases, `openssl list-cipher-algorithms` will display the
available cipher algorithms. `password` is used to derive key and IV,
which must be a `'binary'` encoded string or a [buffer](buffer.html).

It is a [stream](stream.html) that is both readable and writable. The
written data is used to compute the hash. Once the writable side of
the stream is ended, use the `read()` method to get the computed hash
digest. The legacy `update` and `digest` methods are also supported.

## crypto.createCipheriv(algorithm, key, iv)

Creates and returns a cipher object, with the given algorithm, key and
@@ -166,6 +181,11 @@ Class for encrypting data.

Returned by `crypto.createCipher` and `crypto.createCipheriv`.

Cipher objects are [streams](stream.html) that are both readable and
writable. The written plain text data is used to produce the
encrypted data on the the readable side. The legacy `update` and
`final` methods are also supported.

### cipher.update(data, [input_encoding], [output_encoding])

Updates the cipher with `data`, the encoding of which is given in
@@ -213,6 +233,11 @@ Class for decrypting data.

Returned by `crypto.createDecipher` and `crypto.createDecipheriv`.

Decipher objects are [streams](stream.html) that are both readable and
writable. The written enciphered data is used to produce the
plain-text data on the the readable side. The legacy `update` and
`final` methods are also supported.

### decipher.update(data, [input_encoding], [output_encoding])

Updates the decipher with `data`, which is encoded in `'binary'`,
@@ -246,28 +271,33 @@ Creates and returns a signing object, with the given algorithm. On
recent OpenSSL releases, `openssl list-public-key-algorithms` will
display the available signing algorithms. Examples are `'RSA-SHA256'`.

## Class: Signer
## Class: Sign

Class for generating signatures.

Returned by `crypto.createSign`.

### signer.update(data)
Sign objects are writable [streams](stream.html). The written data is
used to generate the signature. Once all of the data has been
written, the `sign` method will return the signature. The legacy
`update` method is also supported.

### sign.update(data)

Updates the signer object with data. This can be called many times
Updates the sign object with data. This can be called many times
with new data as it is streamed.

### signer.sign(private_key, [output_format])
### sign.sign(private_key, [output_format])

Calculates the signature on all the updated data passed through the
signer. `private_key` is a string containing the PEM encoded private
sign. `private_key` is a string containing the PEM encoded private
key for signing.

Returns the signature in `output_format` which can be `'binary'`,
`'hex'` or `'base64'`. If no encoding is provided, then a buffer is
returned.

Note: `signer` object can not be used after `sign()` method been
Note: `sign` object can not be used after `sign()` method been
called.

## crypto.createVerify(algorithm)
@@ -281,6 +311,12 @@ Class for verifying signatures.

Returned by `crypto.createVerify`.

Verify objects are writable [streams](stream.html). The written data
is used to validate against the supplied signature. Once all of the
data has been written, the `verify` method will return true if the
supplied signature is valid. The legacy `update` method is also
supported.

### verifier.update(data)

Updates the verifier object with data. This can be called many times
@@ -469,9 +505,6 @@ default, set the `crypto.DEFAULT_ENCODING` field to 'binary'. Note
that new programs will probably expect buffers, so only use this as a
temporary measure.

Also, a Streaming API will be provided, but this will be done in such
a way as to preserve the legacy API surface.


[createCipher()]: #crypto_crypto_createcipher_algorithm_password
[createCipheriv()]: #crypto_crypto_createcipheriv_algorithm_key_iv
@@ -0,0 +1,63 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

// a duplex stream is just a stream that is both readable and writable.
// Since JS doesn't have multiple prototypal inheritance, this class
// prototypally inherits from Readable, and then parasitically from
// Writable.

module.exports = Duplex;
var util = require('util');
var Readable = require('_stream_readable');
var Writable = require('_stream_writable');

util.inherits(Duplex, Readable);

Object.keys(Writable.prototype).forEach(function(method) {
if (!Duplex.prototype[method])
Duplex.prototype[method] = Writable.prototype[method];
});

function Duplex(options) {
if (!(this instanceof Duplex))
return new Duplex(options);

Readable.call(this, options);
Writable.call(this, options);

this.allowHalfOpen = true;
if (options && options.allowHalfOpen === false)
this.allowHalfOpen = false;

this.once('end', onend);
}

// the no-half-open enforcer
function onend() {
// if we allow half-open state, or if the writable side ended,
// then we're ok.
if (this.allowHalfOpen || this._writableState.ended)
return;

// no more data can be written.
// But allow more writes to happen in this tick.
process.nextTick(this.end.bind(this));
}
@@ -19,18 +19,23 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var zlib = require('zlib');
// a passthrough stream.
// basically just the most minimal sort of Transform stream.
// Every written chunk gets output as-is.

['Deflate', 'Inflate', 'Gzip', 'Gunzip', 'DeflateRaw', 'InflateRaw', 'Unzip']
.forEach(function (name) {
var a = false;
var zStream = new zlib[name]();
zStream.on('close', function () {
a = true;
});
zStream.destroy();
module.exports = PassThrough;

assert.equal(a, true, name+'#destroy() must emit \'close\'');
});
var Transform = require('_stream_transform');
var util = require('util');
util.inherits(PassThrough, Transform);

function PassThrough(options) {
if (!(this instanceof PassThrough))
return new PassThrough(options);

Transform.call(this, options);
}

PassThrough.prototype._transform = function(chunk, output, cb) {
cb(null, chunk);
};