|
@ -1,5 +1,6 @@ |
|
|
var sys = require("sys"); |
|
|
var sys = require("sys"); |
|
|
var fs = require("fs"); |
|
|
var fs = require("fs"); |
|
|
|
|
|
var Utf8Decoder = require("utf8decoder").Utf8Decoder; |
|
|
var events = require("events"); |
|
|
var events = require("events"); |
|
|
var dns = require('dns'); |
|
|
var dns = require('dns'); |
|
|
|
|
|
|
|
@ -381,6 +382,8 @@ function initStream (self) { |
|
|
|
|
|
|
|
|
// Optimization: emit the original buffer with end points
|
|
|
// Optimization: emit the original buffer with end points
|
|
|
if (self.ondata) self.ondata(pool, start, end); |
|
|
if (self.ondata) self.ondata(pool, start, end); |
|
|
|
|
|
} else if (this._decoder) { |
|
|
|
|
|
this._decoder.write(pool.slice(start, end)); |
|
|
} else { |
|
|
} else { |
|
|
var string = pool.toString(self._encoding, start, end); |
|
|
var string = pool.toString(self._encoding, start, end); |
|
|
self.emit('data', string); |
|
|
self.emit('data', string); |
|
@ -713,8 +716,17 @@ Stream.prototype._writeQueueLast = function () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Stream.prototype.setEncoding = function (enc) { |
|
|
Stream.prototype.setEncoding = function (enc) { |
|
|
|
|
|
var self = this; |
|
|
// TODO check values, error out on bad, and deprecation message?
|
|
|
// TODO check values, error out on bad, and deprecation message?
|
|
|
this._encoding = enc.toLowerCase(); |
|
|
this._encoding = enc.toLowerCase(); |
|
|
|
|
|
if (this._encoding == 'utf-8' || this._encoding == 'utf8') { |
|
|
|
|
|
this._decoder = new Utf8Decoder(); |
|
|
|
|
|
this._decoder.onString = function(str) { |
|
|
|
|
|
self.emit('data', str); |
|
|
|
|
|
}; |
|
|
|
|
|
} else if (this._decoder) { |
|
|
|
|
|
delete this._decoder; |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|