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

Function primitiveToUint8Array

lib/internal/streams/iter/from.js:98–110  ·  view source on GitHub ↗

* Convert a primitive chunk to Uint8Array. * - string: UTF-8 encoded * - ArrayBuffer: wrapped as Uint8Array view (no copy) * - ArrayBufferView: converted to Uint8Array view of same memory * @param {string|ArrayBuffer|ArrayBufferView} chunk * @returns {Uint8Array}

(chunk)

Source from the content-addressed store, hash-verified

96 * @returns {Uint8Array}
97 */
98function primitiveToUint8Array(chunk) {
99 if (typeof chunk === 'string') {
100 return toUint8Array(chunk);
101 }
102 if (isAnyArrayBuffer(chunk)) {
103 return new Uint8Array(chunk);
104 }
105 if (isUint8Array(chunk)) {
106 return chunk;
107 }
108 // Other ArrayBufferView types (Int8Array, DataView, etc.)
109 return arrayBufferViewToUint8Array(chunk);
110}
111
112function arrayBufferViewToUint8Array(chunk) {
113 if (isTypedArray(chunk)) {

Callers 4

normalizeSyncValueFunction · 0.85
normalizeAsyncValueFunction · 0.85
fromSyncFunction · 0.85
fromFunction · 0.85

Calls 3

toUint8ArrayFunction · 0.85
isUint8ArrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…