MCPcopy Create free account
hub / github.com/TGX-Android/Publisher / toUtf8

Function toUtf8

main.js:469–495  ·  view source on GitHub ↗
(res, onDone, needBinary)

Source from the content-addressed store, hash-verified

467}
468
469function toUtf8 (res, onDone, needBinary) {
470 const contentType = (res.headers['content-type'] || '').split(';');
471 let encoding = null;
472 for (let i = 0; i < contentType.length; i++) {
473 const keyValue = contentType[i].split('=');
474 if (keyValue.length === 2 && keyValue[0].toLowerCase() === 'charset') {
475 encoding = keyValue[1].toLowerCase();
476 }
477 }
478 let data = [];
479 res.setEncoding('binary');
480 res.on('data', (chunk) => {
481 data.push(Buffer.from(chunk, 'binary'));
482 });
483 res.on('end', () => {
484 const binary = Buffer.concat(data);
485 if (needBinary) {
486 onDone(contentType, binary);
487 } else {
488 if (encoding && encoding !== 'utf-8') {
489 onDone(contentType, iconv.encode(iconv.decode(binary, encoding), 'utf-8'));
490 } else {
491 onDone(contentType, binary.toString('utf-8'));
492 }
493 }
494 });
495}
496
497function getProperty (data, variableName) {
498 variableName = variableName.replace(/\./gi, '\\.');

Callers 4

postHttpFunction · 0.85
fetchHttpFunction · 0.85
uploadHttpFileFunction · 0.85
postHuaweiFormFunction · 0.85

Calls 1

onDoneFunction · 0.85

Tested by

no test coverage detected