Skip to content

Commit

Permalink
Merge pull request #821 from agokhale/pdf-noncompliant
Browse files Browse the repository at this point in the history
Pdf noncompliant
  • Loading branch information
aheckmann authored Sep 19, 2022
2 parents 1ebb09c + 5f536c2 commit 1808616
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ http://github.com/quiiver/magickal-node
## Plugins
[https://github.com/aheckmann/gm/wiki](https://github.com/aheckmann/gm/wiki)

## Tests
node test --integration --only pdf-noncompliant.js

## License

(The MIT License)
Expand Down
6 changes: 5 additions & 1 deletion lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var utils = require('./utils');
var debug = require('debug')('gm');
var series = require('array-series');
var PassThrough = require('stream').PassThrough;
var nuisanceConsumer = require('./nuisanceConsumer');

/**
* Error messaging.
Expand Down Expand Up @@ -286,7 +287,10 @@ module.exports = function (proto) {
, onExit

proc.stdout.on('data', onOut = function (data) {
stdout += data;
if ( nuisanceConsumer.isNuisance( data ) == 1 )
{ /*console.log("elided", data); */ stderr+= data; }
else
{stdout += data;}
});

proc.stderr.on('data', onErr = function (data) {
Expand Down
10 changes: 10 additions & 0 deletions lib/nuisanceConsumer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//issues/820

module.exports = exports = {};
exports.isNuisance = function(instring) {
//console.log ("wat", instring.toString(), typeof(instring));
// scan each emitted line, if it's an error line, remove it
//**** Error: stream operator isn't terminated by valid EOL.
if( instring.toString().indexOf ("**** Error: stream operator isn't terminated by valid EOL.") > 1) { return 1 }
return 0 ;
}
Binary file added test/fixtures/synthetic_invalid.pdf
Binary file not shown.
20 changes: 20 additions & 0 deletions test/pdf-noncompliant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

//https://github.com/aheckmann/gm/issues/820
var assert = require('assert');
var fs = require('fs');
var path = require('path');

module.exports = function (_, dir, finish, gm) {
if (!gm.integration) return finish();

var imagePath = path.join(__dirname, './fixtures/synthetic_invalid.pdf');
var inputStream = fs.createReadStream(imagePath);
gm(inputStream)
.size({ bufferStream: true }, function(err, size) {
if (err) return finish(err);
assert.equal(612, size.width);
assert.equal(792, size.height);
finish();
});
}

0 comments on commit 1808616

Please sign in to comment.