智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
LightingSystemApp-serial/.svn/pristine/9b/9b2f2acc18d38a3ae3d41f379d8...

25 lines
698 B

module.exports = Stream;
var Parser = require("./Parser.js");
var WritableStream = require("readable-stream").Writable;
var StringDecoder = require("string_decoder").StringDecoder;
var Buffer = require("buffer").Buffer;
function Stream(cbs, options){
var parser = this._parser = new Parser(cbs, options);
var decoder = this._decoder = new StringDecoder();
WritableStream.call(this, {decodeStrings: false});
this.once("finish", function(){
parser.end(decoder.end());
});
}
require("inherits")(Stream, WritableStream);
WritableStream.prototype._write = function(chunk, encoding, cb){
if(chunk instanceof Buffer) chunk = this._decoder.write(chunk);
this._parser.write(chunk);
cb();
};