Skip to content

Commit

Permalink
Bugfix: Fix application/pdf response type handling
Browse files Browse the repository at this point in the history
This commit corresponds to docusign#305 and provides a fix in line with the suggestions made therein.
  • Loading branch information
andercs authored Aug 26, 2022
1 parent f18e860 commit 74422ec
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,16 +569,15 @@
}

if (request.header['Accept'] === 'application/pdf') {
// Copy of https://github.com/visionmedia/superagent/blob/master/src/node/parsers/image.js until superagent can be upgraded
request.parse( function (res, fn) {
res.data = '';
res.setEncoding('binary');
res.on( 'data', function (chunk) { res.data += chunk; } );
res.on( 'end', function () {
try {
fn( null, res.data );
} catch ( err ) {
fn( err );
}
res.data = []; // Binary data needs binary storage

res.on('data', (chunk) => {
res.data.push(chunk);
});
res.on('end', () => {
fn(null, Buffer.concat(res.data));
});
})
}
Expand Down

0 comments on commit 74422ec

Please sign in to comment.