Skip to content

Commit

Permalink
Merge pull request Automattic#1034 from binarykitchen/master
Browse files Browse the repository at this point in the history
Add unit test for valid jpeg EOI marker
  • Loading branch information
LinusU committed Nov 15, 2017
2 parents bd72c0c + af2d6e7 commit 7f1be7b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/canvas.test.js
Expand Up @@ -1289,6 +1289,26 @@ describe('Canvas', function () {
});
});

// based on https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format
// end of image marker (FF D9) must exist to maintain JPEG standards
it('EOI at end of Canvas#jpegStream()', function (done) {
var canvas = createCanvas(640, 480);
var stream = canvas.jpegStream();
var chunks = []
stream.on('data', function(chunk){
chunks.push(chunk)
});
stream.on('end', function(){
var lastTwoBytes = chunks.pop().slice(-2)
assert.equal(0xFF, lastTwoBytes[0]);
assert.equal(0xD9, lastTwoBytes[1]);
done();
});
stream.on('error', function(err) {
done(err);
});
});

it('Canvas#jpegStream() should clamp buffer size (#674)', function (done) {
var c = createCanvas(10, 10);
var SIZE = 10 * 1024 * 1024;
Expand Down

0 comments on commit 7f1be7b

Please sign in to comment.