mirror of
https://gitee.com/dgflash/oops-framework.git
synced 2026-05-22 14:37:06 +08:00
15 lines
400 B
JavaScript
15 lines
400 B
JavaScript
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
const textDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8');
|
|
|
|
function bufferToString(chunk) {
|
|
if (typeof chunk === 'string') {
|
|
return chunk;
|
|
}
|
|
if (textDecoder) {
|
|
return textDecoder.decode(chunk);
|
|
}
|
|
return chunk.toString();
|
|
}
|
|
|
|
exports.bufferToString = bufferToString;
|