Browse Source

Safe constructors for fs.ReadStream and fs.WriteStream

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
bbbcd1fee0
  1. 4
      lib/fs.js
  2. 2
      test/simple/test-fs-read-stream.js
  3. 2
      test/simple/test-fs-write-stream.js

4
lib/fs.js

@ -598,6 +598,8 @@ fs.createReadStream = function(path, options) {
};
var ReadStream = fs.ReadStream = function(path, options) {
if (!(this instanceof ReadStream)) return new ReadStream(path, options);
events.EventEmitter.call(this);
var self = this;
@ -794,6 +796,8 @@ fs.createWriteStream = function(path, options) {
};
var WriteStream = fs.WriteStream = function(path, options) {
if (!(this instanceof WriteStream)) return new WriteStream(path, options);
events.EventEmitter.call(this);
this.path = path;

2
test/simple/test-fs-read-stream.js

@ -15,7 +15,7 @@ callbacks = { open: 0, end: 0, close: 0, destroy: 0 };
paused = false;
file = fs.createReadStream(fn);
file = fs.ReadStream(fn);
file.addListener('open', function(fd) {
file.length = 0;

2
test/simple/test-fs-write-stream.js

@ -7,7 +7,7 @@ var path = require('path'),
var file = path.join(common.fixturesDir, "write.txt");
(function() {
var stream = fs.createWriteStream(file),
var stream = fs.WriteStream(file),
_fs_close = fs.close;
fs.close = function(fd) {

Loading…
Cancel
Save