diff --git a/Readme.md b/Readme.md index c0285d048..66a649316 100644 --- a/Readme.md +++ b/Readme.md @@ -138,8 +138,6 @@ stream.on('end', function(){ }); ``` -Currently _only_ sync streaming is supported, however we plan on supporting async streaming as well (of course :) ). Until then the `Canvas#toBuffer(callback)` alternative is async utilizing `eio_custom()`. - To encode indexed PNGs from canvases with `pixelFormat: 'A8'` or `'A1'`, provide an options object: ```js diff --git a/lib/canvas.js b/lib/canvas.js index 4cc567afe..918a33f40 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -64,23 +64,6 @@ Canvas.prototype.createPNGStream = function(options){ return new PNGStream(this, false, options); }; -/** - * Create a synchronous `PNGStream` for `this` canvas. - * - * @param {Object} options - * @param {Uint8ClampedArray} options.palette Provide for indexed PNG encoding. - * entries should be R-G-B-A values. - * @param {Number} options.backgroundIndex Optional index of background color - * for indexed PNGs. Defaults to 0. - * @return {PNGStream} - * @api public - */ - -Canvas.prototype.syncPNGStream = -Canvas.prototype.createSyncPNGStream = function(options){ - return new PNGStream(this, true, options); -}; - /** * Create a `PDFStream` for `this` canvas. * @@ -93,18 +76,6 @@ Canvas.prototype.createPDFStream = function(){ return new PDFStream(this); }; -/** - * Create a synchronous `PDFStream` for `this` canvas. - * - * @return {PDFStream} - * @api public - */ - -Canvas.prototype.syncPDFStream = -Canvas.prototype.createSyncPDFStream = function(){ - return new PDFStream(this, true); -}; - /** * Create a `JPEGStream` for `this` canvas. * @@ -115,19 +86,6 @@ Canvas.prototype.createSyncPDFStream = function(){ Canvas.prototype.jpegStream = Canvas.prototype.createJPEGStream = function(options){ - return this.createSyncJPEGStream(options); -}; - -/** - * Create a synchronous `JPEGStream` for `this` canvas. - * - * @param {Object} options - * @return {JPEGStream} - * @api public - */ - -Canvas.prototype.syncJPEGStream = -Canvas.prototype.createSyncJPEGStream = function(options){ options = options || {}; // Don't allow the buffer size to exceed the size of the canvas (#674) var maxBufSize = this.width * this.height * 4; diff --git a/lib/jpegstream.js b/lib/jpegstream.js index 5705a9aa3..efae2f776 100644 --- a/lib/jpegstream.js +++ b/lib/jpegstream.js @@ -26,11 +26,10 @@ var util = require('util'); * stream.pipe(out); * * @param {Canvas} canvas - * @param {Boolean} sync * @api public */ -var JPEGStream = module.exports = function JPEGStream(canvas, options, sync) { +var JPEGStream = module.exports = function JPEGStream(canvas, options) { if (!(this instanceof JPEGStream)) { throw new TypeError("Class constructors cannot be invoked without 'new'"); } @@ -38,16 +37,8 @@ var JPEGStream = module.exports = function JPEGStream(canvas, options, sync) { Readable.call(this); var self = this; - var method = sync - ? 'streamJPEGSync' - : 'streamJPEG'; this.options = options; - this.sync = sync; this.canvas = canvas; - - // TODO: implement async - if ('streamJPEG' == method) method = 'streamJPEGSync'; - this.method = method; }; util.inherits(JPEGStream, Readable); @@ -63,7 +54,7 @@ JPEGStream.prototype._read = function _read() { var bufsize = this.options.bufsize; var quality = this.options.quality; var progressive = this.options.progressive; - self.canvas[method](bufsize, quality, progressive, function(err, chunk){ + self.canvas.streamJPEGSync(bufsize, quality, progressive, function(err, chunk){ if (err) { self.emit('error', err); } else if (chunk) { diff --git a/lib/pdfstream.js b/lib/pdfstream.js index 084ad3a22..837a034c3 100644 --- a/lib/pdfstream.js +++ b/lib/pdfstream.js @@ -24,27 +24,17 @@ var util = require('util'); * stream.pipe(out); * * @param {Canvas} canvas - * @param {Boolean} sync * @api public */ -var PDFStream = module.exports = function PDFStream(canvas, sync) { +var PDFStream = module.exports = function PDFStream(canvas) { if (!(this instanceof PDFStream)) { throw new TypeError("Class constructors cannot be invoked without 'new'"); } Readable.call(this); - var self = this - , method = sync - ? 'streamPDFSync' - : 'streamPDF'; - this.sync = sync; this.canvas = canvas; - - // TODO: implement async - if ('streamPDF' == method) method = 'streamPDFSync'; - this.method = method; }; util.inherits(PDFStream, Readable); @@ -56,7 +46,7 @@ PDFStream.prototype._read = function _read() { // call canvas.streamPDFSync once and let it emit data at will. this._read = noop; var self = this; - self.canvas[self.method](function(err, chunk, len){ + self.canvas.streamPDFSync(function(err, chunk, len){ if (err) { self.emit('error', err); } else if (len) { diff --git a/lib/pngstream.js b/lib/pngstream.js index fb1469185..a774d97ac 100644 --- a/lib/pngstream.js +++ b/lib/pngstream.js @@ -26,7 +26,6 @@ var util = require('util'); * stream.pipe(out); * * @param {Canvas} canvas - * @param {Boolean} sync * @param {Object} options * @param {Uint8ClampedArray} options.palette Provide for indexed PNG encoding. * entries should be R-G-B-A values. @@ -35,7 +34,7 @@ var util = require('util'); * @api public */ -var PNGStream = module.exports = function PNGStream(canvas, sync, options) { +var PNGStream = module.exports = function PNGStream(canvas, options) { if (!(this instanceof PNGStream)) { throw new TypeError("Class constructors cannot be invoked without 'new'"); } @@ -43,16 +42,8 @@ var PNGStream = module.exports = function PNGStream(canvas, sync, options) { Readable.call(this); var self = this; - var method = sync - ? 'streamPNGSync' - : 'streamPNG'; - this.sync = sync; this.canvas = canvas; this.options = options || {}; - - // TODO: implement async - if ('streamPNG' === method) method = 'streamPNGSync'; - this.method = method; }; util.inherits(PNGStream, Readable); @@ -64,7 +55,7 @@ PNGStream.prototype._read = function _read() { // call canvas.streamPNGSync once and let it emit data at will. this._read = noop; var self = this; - self.canvas[self.method](function(err, chunk, len){ + self.canvas.streamPNGSync(function(err, chunk, len){ if (err) { self.emit('error', err); } else if (len) { diff --git a/test/canvas.test.js b/test/canvas.test.js index daf4f2fa0..78c59e60e 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -1152,9 +1152,9 @@ describe('Canvas', function () { }); }); - it('Canvas#createSyncPNGStream()', function (done) { + it('Canvas#createPNGStream()', function (done) { var canvas = createCanvas(20, 20); - var stream = canvas.createSyncPNGStream(); + var stream = canvas.createPNGStream(); assert(stream instanceof Readable); var firstChunk = true; stream.on('data', function(chunk){ @@ -1171,9 +1171,9 @@ describe('Canvas', function () { }); }); - it('Canvas#createSyncPDFStream()', function (done) { + it('Canvas#createPDFStream()', function (done) { var canvas = createCanvas(20, 20, 'pdf'); - var stream = canvas.createSyncPDFStream(); + var stream = canvas.createPDFStream(); assert(stream instanceof Readable); var firstChunk = true; stream.on('data', function (chunk) {