-
Notifications
You must be signed in to change notification settings - Fork 1.2k
jpegstream is broken since 1.2.6 #674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Really big - 10 mb for file 300kb |
Can you provide your test code please? |
Sure: var canvas = require('canvas');
var c = new canvas(2048, 1536);
c.context = c.getContext('2d');
for (i=0; i<2048*1536; i++) {
c.context.fillStyle = "rgb("+ i%255 +","+i%255+","+i%255+")";
c.context.fillRect(i%2048, parseInt(i/2048), 1, 1);
}
var stream = c.jpegStream({
bufsize: 1024*1024*10 // output buffer size in bytes, default: 4096
, quality: 75 // JPEG quality (0-100) default: 75
, progressive: false // true for progressive compression, default: false
});
var bufs = [];
stream.on('data', function(d){ bufs.push(d); });
stream.on('end', function() {
var buf = Buffer.concat(bufs);
require('fs').writeFileSync(require('path').join(__dirname, '/test.jpg'), buf);
console.log('all done', buf.length);
}); With latest version i have: 'all done 10485760' |
The |
Hm, really missed that 10485760 = 1024 * 1024 * 10. Maybe it is not issue. Thanks. |
We should probably clamp the length of the returned buffer though so this
can't happen...
|
This still feels like a bug to me |
Another thing that I discovered just now is that the stream isn't a spec-compliant It also emits |
Okay, here is some very short code demonstrating the issue: const assert = require('assert')
const Canvas = require('canvas')
const SIZE = 10 * 1024 * 1024
let c = new Canvas(10, 10)
let s = c.jpegStream({ bufsize: SIZE })
s.on('data', function (chunk) {
assert(chunk.length < SIZE, `Expected chunk size (${chunk.length}) to be smaller than maximum (${SIZE})`)
}) |
After 1.2.6 jpeg stream makes for me really big files with some trash. Tested on mac and linux.
The text was updated successfully, but these errors were encountered: