Merge pull request #4522 from Nriver/master

fix decoding issue for request data chunks
pull/13/head
zadam 2023-12-27 22:58:27 +07:00 committed by GitHub
commit a3783131a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

@ -63,10 +63,15 @@ function exec(opts) {
}
let responseStr = '';
let chunks = [];
response.on('data', chunk => responseStr += chunk);
response.on('data', chunk => chunks.push(chunk));
response.on('end', () => {
// use Buffer instead of string concatenation to avoid implicit decoding for each chunk
// decode the entire data chunks explicitly as utf-8
responseStr = Buffer.concat(chunks).toString('utf-8')
if ([200, 201, 204].includes(response.statusCode)) {
try {
const jsonObj = responseStr.trim() ? JSON.parse(responseStr) : null;