1 var Stream = require('stream').Stream
3 module.exports = legacy
7 ReadStream: ReadStream,
8 WriteStream: WriteStream
11 function ReadStream (path, options) {
12 if (!(this instanceof ReadStream)) return new ReadStream(path, options);
24 this.mode = 438; /*=0666*/
25 this.bufferSize = 64 * 1024;
27 options = options || {};
29 // Mixin options into this
30 var keys = Object.keys(options);
31 for (var index = 0, length = keys.length; index < length; index++) {
32 var key = keys[index];
33 this[key] = options[key];
36 if (this.encoding) this.setEncoding(this.encoding);
38 if (this.start !== undefined) {
39 if ('number' !== typeof this.start) {
40 throw TypeError('start must be a Number');
42 if (this.end === undefined) {
44 } else if ('number' !== typeof this.end) {
45 throw TypeError('end must be a Number');
48 if (this.start > this.end) {
49 throw new Error('start must be <= end');
52 this.pos = this.start;
55 if (this.fd !== null) {
56 process.nextTick(function() {
62 fs.open(this.path, this.flags, this.mode, function (err, fd) {
64 self.emit('error', err);
65 self.readable = false;
70 self.emit('open', fd);
75 function WriteStream (path, options) {
76 if (!(this instanceof WriteStream)) return new WriteStream(path, options);
85 this.encoding = 'binary';
86 this.mode = 438; /*=0666*/
87 this.bytesWritten = 0;
89 options = options || {};
91 // Mixin options into this
92 var keys = Object.keys(options);
93 for (var index = 0, length = keys.length; index < length; index++) {
94 var key = keys[index];
95 this[key] = options[key];
98 if (this.start !== undefined) {
99 if ('number' !== typeof this.start) {
100 throw TypeError('start must be a Number');
102 if (this.start < 0) {
103 throw new Error('start must be >= zero');
106 this.pos = this.start;
112 if (this.fd === null) {
113 this._open = fs.open;
114 this._queue.push([this._open, this.path, this.flags, this.mode, undefined]);