doccam-pi/lib/memWrite.js
Hiro Protagonist f19860cf16 nice init
2016-08-26 14:35:18 +12:00

27 lines
794 B
JavaScript

var stream = require('stream');
var Writable = stream.Writable ||
require('readable-stream').Writable;
var util = require('util');
function WMStrm(options) {
// allow use without new operator
if (!(this instanceof WMStrm)) {
return new WMStrm(options);
}
Writable.call(this, options); // init super
this.memStore = new Buffer(''); // empty
}
util.inherits(WMStrm, Writable);
WMStrm.prototype._write = function (chunk, enc, cb) {
// our memory store stores things in buffers
var buffer = (Buffer.isBuffer(chunk)) ?
chunk : // already is Buffer use it
new Buffer(chunk, enc); // string, convert
// concat to the buffer already there
this.memStore = Buffer.concat([this.memStore, buffer]);
cb();
};
module.exports = WMStrm;;