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

Function exportString

lib/ffi.js:195–227  ·  view source on GitHub ↗
(str, data, len, encoding = 'utf8')

Source from the content-addressed store, hash-verified

193}
194
195function exportString(str, data, len, encoding = 'utf8') {
196 checkFFIPermission();
197 validateString(str, 'string');
198 validateString(encoding, 'encoding');
199 validateInteger(len, 'len', 0);
200
201 let terminatorSize;
202
203 switch (encoding.toLowerCase()) {
204 case 'ucs2':
205 case 'ucs-2':
206 case 'utf16le':
207 case 'utf-16le':
208 terminatorSize = 2;
209 break;
210 default:
211 terminatorSize = 1;
212 break;
213 }
214
215 const sourceBuffer = Buffer.from(str, encoding);
216 const requiredLength = sourceBuffer.length + terminatorSize;
217
218 if (len < requiredLength) {
219 throw new ERR_OUT_OF_RANGE('len', `>= ${requiredLength}`, len);
220 }
221
222 const targetBuffer = toBuffer(data, len, false);
223 const dataLength = sourceBuffer.length;
224
225 sourceBuffer.copy(targetBuffer, 0, 0, dataLength);
226 targetBuffer.fill(0, dataLength, dataLength + terminatorSize);
227}
228
229function exportBuffer(source, data, len) {
230 checkFFIPermission();

Callers

nothing calls this directly

Calls 5

checkFFIPermissionFunction · 0.85
fillMethod · 0.80
copyMethod · 0.65
toBufferFunction · 0.50
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…