mirror of https://github.com/nodejs/node.git
Safe constructors for fs.ReadStream and fs.WriteStream
parent
6da0593162
commit
bbbcd1fee0
|
@ -598,6 +598,8 @@ fs.createReadStream = function(path, options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var ReadStream = fs.ReadStream = function(path, options) {
|
var ReadStream = fs.ReadStream = function(path, options) {
|
||||||
|
if (!(this instanceof ReadStream)) return new ReadStream(path, options);
|
||||||
|
|
||||||
events.EventEmitter.call(this);
|
events.EventEmitter.call(this);
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -794,6 +796,8 @@ fs.createWriteStream = function(path, options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var WriteStream = fs.WriteStream = function(path, options) {
|
var WriteStream = fs.WriteStream = function(path, options) {
|
||||||
|
if (!(this instanceof WriteStream)) return new WriteStream(path, options);
|
||||||
|
|
||||||
events.EventEmitter.call(this);
|
events.EventEmitter.call(this);
|
||||||
|
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
|
|
@ -15,7 +15,7 @@ callbacks = { open: 0, end: 0, close: 0, destroy: 0 };
|
||||||
|
|
||||||
paused = false;
|
paused = false;
|
||||||
|
|
||||||
file = fs.createReadStream(fn);
|
file = fs.ReadStream(fn);
|
||||||
|
|
||||||
file.addListener('open', function(fd) {
|
file.addListener('open', function(fd) {
|
||||||
file.length = 0;
|
file.length = 0;
|
||||||
|
|
|
@ -7,7 +7,7 @@ var path = require('path'),
|
||||||
var file = path.join(common.fixturesDir, "write.txt");
|
var file = path.join(common.fixturesDir, "write.txt");
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var stream = fs.createWriteStream(file),
|
var stream = fs.WriteStream(file),
|
||||||
_fs_close = fs.close;
|
_fs_close = fs.close;
|
||||||
|
|
||||||
fs.close = function(fd) {
|
fs.close = function(fd) {
|
||||||
|
|
Loading…
Reference in New Issue