interface
ffi.CStringConstructor
interface CStringConstructor
- constructor CStringConstructor(byteOffset?: number,byteLength?: number): string;
Read a UTF-8 encoded C string into a JavaScript string.
If
byteLengthis not provided, the string is assumed to be null-terminated. The result is a clone of the C string, so it is safe to keep using it after the memory atptrhas been freed. A falsyptryields an empty string.Bun catches some invalid pointers, but not all. Passing an invalid pointer, or reading past the end of the memory it points to, can crash the program or cause undefined behavior.
@param ptrThe pointer to the C string
@param byteOffsetbytes to skip before reading
@param byteLengthbytes to read
var ptr = lib.symbols.getVersion(); console.log(new CString(ptr));
Referenced types
type Pointer = number & { __pointer__: null }