node-gfx / node-canvas-prebuilt

Repo used to build binaries for node-canvas on CI
170 stars 31 forks source link

data-uri break the process with no error #52

Closed sarvaje closed 6 years ago

sarvaje commented 6 years ago

When you run this code, the process break without any error.

const datauri = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
const Canvas = require('canvas-prebuilt');

const image = new Canvas.Image();

image.onerror = function (e) {
    console.log(e);
}
console.log('before');
image.src = datauri;
console.log('after');

Expected output:

before
Error: error while reading from input stream
after

Current output:

before

If I change to canvas everything works as expected (any 1.6.x version).

It works with version 2.0.0-alpha.13 but I can't use it because it is use in jsdom and they don't support version 2 yet.

Maybe this will be fixed after https://github.com/node-gfx/node-canvas-prebuilt/issues/51 is done.

chearon commented 6 years ago

If I change to canvas everything works as expected (any 1.6.x version).

Are you sure? I don't think that was implemented until Automattic/node-canvas#1193. canvas@next or canvas-prebuilt@next

sarvaje commented 6 years ago

This is working fine with version 1.6.11.

But just for the record:

Are you sure? I don't think that was implemented until Automattic/node-canvas#1193. canvas@next or canvas-prebuilt@next

Sorry, I though that src was supported in all the versions, but in fact I was using this code:

const dataURL = require("data-urls");
const data = dataURL('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
const Canvas = require('canvas-prebuilt');

const image = new Canvas.Image();

image.onerror = function (e) {
    console.log(e);
}
console.log('before');
image.source = data.body;
console.log('after');

I was expecting an error, but the script finished suddenly in image.source = data.body.

But as I said, this is an issue from the past :)

Thanks!!

chearon commented 6 years ago

Oops, you're right, I was thinking of http-style URLs. Glad that fixed it for you.