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