MCPcopy Index your code
hub / github.com/nodejs/node / toUint8Array

Function toUint8Array

lib/internal/streams/iter/utils.js:99–107  ·  view source on GitHub ↗

* Convert a chunk (string or Uint8Array) to Uint8Array. * Strings are UTF-8 encoded. * @param {Uint8Array|string} chunk * @returns {Uint8Array}

(chunk)

Source from the content-addressed store, hash-verified

97 * @returns {Uint8Array}
98 */
99function toUint8Array(chunk) {
100 if (typeof chunk === 'string') {
101 return encoder.encode(chunk);
102 }
103 if (!isUint8Array(chunk)) {
104 throw new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Uint8Array'], chunk);
105 }
106 return chunk;
107}
108
109/**
110 * Check if all chunks in an array are already Uint8Array (no strings).

Callers 15

writeSyncMethod · 0.85
writeChunksFunction · 0.85
writeFunction · 0.85
writevFunction · 0.85
writeMethod · 0.85
writeSyncMethod · 0.85
primitiveToUint8ArrayFunction · 0.85
convertChunksFunction · 0.85

Calls 2

isUint8ArrayFunction · 0.85
encodeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…