browser-buffer-decode.js 386 B

1234567891011121314
  1. // eslint-disable-next-line node/no-unsupported-features/node-builtins
  2. const textDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8');
  3. function bufferToString(chunk) {
  4. if (typeof chunk === 'string') {
  5. return chunk;
  6. }
  7. if (textDecoder) {
  8. return textDecoder.decode(chunk);
  9. }
  10. return chunk.toString();
  11. }
  12. exports.bufferToString = bufferToString;