]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/sha/node_modules/readable-stream/lib/_stream_duplex.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / sha / node_modules / readable-stream / lib / _stream_duplex.js
1 // a duplex stream is just a stream that is both readable and writable.
2 // Since JS doesn't have multiple prototypal inheritance, this class
3 // prototypally inherits from Readable, and then parasitically from
4 // Writable.
5
6 'use strict';
7
8 /*<replacement>*/
9 var objectKeys = Object.keys || function (obj) {
10   var keys = [];
11   for (var key in obj) keys.push(key);
12   return keys;
13 }
14 /*</replacement>*/
15
16
17 module.exports = Duplex;
18
19 /*<replacement>*/
20 var processNextTick = require('process-nextick-args');
21 /*</replacement>*/
22
23
24
25 /*<replacement>*/
26 var util = require('core-util-is');
27 util.inherits = require('inherits');
28 /*</replacement>*/
29
30 var Readable = require('./_stream_readable');
31 var Writable = require('./_stream_writable');
32
33 util.inherits(Duplex, Readable);
34
35 var keys = objectKeys(Writable.prototype);
36 for (var v = 0; v < keys.length; v++) {
37   var method = keys[v];
38   if (!Duplex.prototype[method])
39     Duplex.prototype[method] = Writable.prototype[method];
40 }
41
42 function Duplex(options) {
43   if (!(this instanceof Duplex))
44     return new Duplex(options);
45
46   Readable.call(this, options);
47   Writable.call(this, options);
48
49   if (options && options.readable === false)
50     this.readable = false;
51
52   if (options && options.writable === false)
53     this.writable = false;
54
55   this.allowHalfOpen = true;
56   if (options && options.allowHalfOpen === false)
57     this.allowHalfOpen = false;
58
59   this.once('end', onend);
60 }
61
62 // the no-half-open enforcer
63 function onend() {
64   // if we allow half-open state, or if the writable side ended,
65   // then we're ok.
66   if (this.allowHalfOpen || this._writableState.ended)
67     return;
68
69   // no more data can be written.
70   // But allow more writes to happen in this tick.
71   processNextTick(onEndNT, this);
72 }
73
74 function onEndNT(self) {
75   self.end();
76 }
77
78 function forEach (xs, f) {
79   for (var i = 0, l = xs.length; i < l; i++) {
80     f(xs[i], i);
81   }
82 }