pdfstream.js 679 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict'
  2. /*!
  3. * Canvas - PDFStream
  4. */
  5. const { Readable } = require('stream')
  6. function noop () {}
  7. class PDFStream extends Readable {
  8. constructor (canvas, options) {
  9. super()
  10. this.canvas = canvas
  11. this.options = options
  12. }
  13. _read () {
  14. // For now we're not controlling the c++ code's data emission, so we only
  15. // call canvas.streamPDFSync once and let it emit data at will.
  16. this._read = noop
  17. this.canvas.streamPDFSync((err, chunk, len) => {
  18. if (err) {
  19. this.emit('error', err)
  20. } else if (len) {
  21. this.push(chunk)
  22. } else {
  23. this.push(null)
  24. }
  25. }, this.options)
  26. }
  27. }
  28. module.exports = PDFStream