data-man-readstream.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* global DataMan */
  2. var PassThrough = Npm.require('stream').PassThrough;
  3. /**
  4. * @method DataMan.ReadStream
  5. * @public
  6. * @constructor
  7. * @param {ReadStream} stream
  8. * @param {String} type The data content (MIME) type.
  9. */
  10. DataMan.ReadStream = function DataManBuffer(stream, type) {
  11. var self = this;
  12. // Create a bufferable / paused new stream...
  13. var pt = new PassThrough();
  14. // Pipe provided read stream into pass-through stream
  15. stream.pipe(pt);
  16. // Set pass-through stream reference
  17. self.stream = pt;
  18. // Set type as provided
  19. self._type = type;
  20. };
  21. /**
  22. * @method DataMan.ReadStream.prototype.getBuffer
  23. * @private
  24. * @param {function} callback callback(err, buffer)
  25. * @returns {undefined}
  26. *
  27. * Passes a Buffer representing the data to a callback.
  28. */
  29. DataMan.ReadStream.prototype.getBuffer = function dataManReadStreamGetBuffer(/*callback*/) {
  30. // TODO implement as passthrough stream?
  31. };
  32. /**
  33. * @method DataMan.ReadStream.prototype.getDataUri
  34. * @private
  35. * @param {function} callback callback(err, dataUri)
  36. *
  37. * Passes a data URI representing the data in the stream to a callback.
  38. */
  39. DataMan.ReadStream.prototype.getDataUri = function dataManReadStreamGetDataUri(/*callback*/) {
  40. // TODO implement as passthrough stream?
  41. };
  42. /**
  43. * @method DataMan.ReadStream.prototype.createReadStream
  44. * @private
  45. *
  46. * Returns a read stream for the data.
  47. */
  48. DataMan.ReadStream.prototype.createReadStream = function dataManReadStreamCreateReadStream() {
  49. return this.stream;
  50. };
  51. /**
  52. * @method DataMan.ReadStream.prototype.size
  53. * @param {function} callback callback(err, size)
  54. * @private
  55. *
  56. * Passes the size in bytes of the data in the stream to a callback.
  57. */
  58. DataMan.ReadStream.prototype.size = function dataManReadStreamSize(callback) {
  59. callback(0); // will determine from stream later
  60. };
  61. /**
  62. * @method DataMan.ReadStream.prototype.type
  63. * @private
  64. *
  65. * Returns the type of the data.
  66. */
  67. DataMan.ReadStream.prototype.type = function dataManReadStreamType() {
  68. return this._type;
  69. };