Tweaks
- Add 'writeable' property - Renamed pump->flush - Use sys.mixin instead of process.mixin
This commit is contained in:
parent
61785afb3d
commit
18a70ffda1
25
lib/fs.js
25
lib/fs.js
@ -1,3 +1,5 @@
|
|||||||
|
var sys = require('sys');
|
||||||
|
|
||||||
exports.Stats = process.Stats;
|
exports.Stats = process.Stats;
|
||||||
|
|
||||||
process.Stats.prototype._checkModeProperty = function (property) {
|
process.Stats.prototype._checkModeProperty = function (property) {
|
||||||
@ -383,13 +385,13 @@ exports.fileWriteStream = function(path, options) {
|
|||||||
var FileWriteStream = exports.FileWriteStream = function(path, options) {
|
var FileWriteStream = exports.FileWriteStream = function(path, options) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.fd = null;
|
this.fd = null;
|
||||||
this.closed = false;
|
this.writeable = true;
|
||||||
|
|
||||||
this.flags = 'w';
|
this.flags = 'w';
|
||||||
this.encoding = 'binary';
|
this.encoding = 'binary';
|
||||||
this.mode = 0666;
|
this.mode = 0666;
|
||||||
|
|
||||||
process.mixin(this, options || {});
|
sys.mixin(this, options || {});
|
||||||
|
|
||||||
var
|
var
|
||||||
self = this,
|
self = this,
|
||||||
@ -398,7 +400,7 @@ var FileWriteStream = exports.FileWriteStream = function(path, options) {
|
|||||||
|
|
||||||
queue.push([fs.open, this.path, this.flags, this.mode]);
|
queue.push([fs.open, this.path, this.flags, this.mode]);
|
||||||
|
|
||||||
function pump() {
|
function flush() {
|
||||||
if (busy) {
|
if (busy) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -416,6 +418,7 @@ var FileWriteStream = exports.FileWriteStream = function(path, options) {
|
|||||||
busy = false;
|
busy = false;
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
self.writeable = false;
|
||||||
self.emit('error', err);
|
self.emit('error', err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -426,13 +429,13 @@ var FileWriteStream = exports.FileWriteStream = function(path, options) {
|
|||||||
self.emit('open', self.fd);
|
self.emit('open', self.fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop pumping after close
|
// stop flushing after close
|
||||||
if (method === fs.close) {
|
if (method === fs.close) {
|
||||||
self.emit('close');
|
self.emit('close');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pump();
|
flush();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Inject the file pointer
|
// Inject the file pointer
|
||||||
@ -444,21 +447,21 @@ var FileWriteStream = exports.FileWriteStream = function(path, options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.write = function(data) {
|
this.write = function(data) {
|
||||||
if (this.closed) {
|
if (!this.writeable) {
|
||||||
throw new Error('stream already closed');
|
throw new Error('stream not writeable');
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.push([fs.write, data, undefined, this.encoding]);
|
queue.push([fs.write, data, undefined, this.encoding]);
|
||||||
pump();
|
flush();
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.close = function() {
|
this.close = function() {
|
||||||
this.closed = true;
|
this.writeable = false;
|
||||||
queue.push([fs.close,]);
|
queue.push([fs.close,]);
|
||||||
pump();
|
flush();
|
||||||
};
|
};
|
||||||
|
|
||||||
pump();
|
flush();
|
||||||
};
|
};
|
||||||
FileWriteStream.prototype.__proto__ = process.EventEmitter.prototype;
|
FileWriteStream.prototype.__proto__ = process.EventEmitter.prototype;
|
Loading…
x
Reference in New Issue
Block a user