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 3b53d38
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,15 +570,13 @@

if (request.header['Accept'] === 'application/pdf') {
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 3b53d38

Please sign in to comment.