index.js 685 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var util = require('util');
  3. var stream = require('stream');
  4. module.exports.createReadStream = function (object, options) {
  5. return new MultiStream (object, options);
  6. };
  7. var MultiStream = function (object, options) {
  8. if (object instanceof Buffer || typeof object === 'string') {
  9. options = options || {};
  10. stream.Readable.call(this, {
  11. highWaterMark: options.highWaterMark,
  12. encoding: options.encoding
  13. });
  14. } else {
  15. stream.Readable.call(this, { objectMode: true });
  16. }
  17. this._object = object;
  18. };
  19. util.inherits(MultiStream, stream.Readable);
  20. MultiStream.prototype._read = function () {
  21. this.push(this._object);
  22. this._object = null;
  23. };