CTIO(3CTYPE)
π CTIO π
β the 3CTYPE manual, but make it make sense
okay bestie so listen: this is the ctype manual page, page CTIO(3CTYPE) if you're being β¨officialβ¨ about it β it's literally just integer and float operations and honestly it's giving "I do one thing and I ate." No cap.
β¨ NAME β¨
ctio, ruint8, ruint16, ruint32, ruint64, wuint8, wuint16, wuint32, wuint64, rsint8, rsint16, rsint32, rsint64, wsint8, wsint16, wsint32, wsint64, rfloat, rdouble, wfloat, wdouble β integer and float operations π§
πΈ SYNOPSIS πΈ
okay so first you gotta get the module:
var mod_ctype = require('ctype');
then the reads π
Number mod_ctype.ruint8(Buffer buf, String endian, Number offset);
Number mod_ctype.ruint16(Buffer buf, String endian, Number offset);
Number mod_ctype.ruint32(Buffer buf, String endian, Number offset);
Number[2] mod_ctype.ruint64(Buffer buf, String endian, Number offset);
Number mod_ctype.rsint8(Buffer buf, String endian, Number offset);
Number mod_ctype.rsint16(Buffer buf, String endian, Number offset);
Number mod_ctype.rsint32(Buffer buf, String endian, Number offset);
Number[2] mod_ctype.rsint64(Buffer buf, String endian, Number offset);
Number mod_ctype.rfloat(Buffer buf, String endian, Number offset);
Number mod_ctype.rdouble(Buffer buf, String endian, Number offset);
and the writes π (notice the argument order flips, value comes first β lowkey iconic of it)
void mod_ctype.wuint8(Number value, String endian, Buffer buf, Number offset);
void mod_ctype.wuint16(Number value, String endian, Buffer buf, Number offset);
void mod_ctype.wuint32(Number value, String endian, Buffer buf, Number offset);
void mod_ctype.wuint64(Number[2] value, String endian, Buffer buf, Number offset);
void mod_ctype.wsint8(Number value, String endian, Buffer buf, Number offset);
void mod_ctype.wsint16(Number value, String endian, Buffer buf, Number offset);
void mod_ctype.wsint32(Number value, String endian, Buffer buf, Number offset);
void mod_ctype.wsint64(Number[2] value, String endian, Buffer buf, Number offset);
void mod_ctype.wfloat(Number value, String endian, Buffer buf, Number offset);
void mod_ctype.wdouble(Number value, String endian, Buffer buf, Number offset);
π¦ DESCRIPTION π¦
okay so the deets, bestie, let's break down the arguments because they're literally the whole personality of this module π
bufβ this is a valid buffer, like the kind you get from callingnew Buffer(). that's the vibe. that's where the bytes live.endianβ either the string'big'or the string'little'(nothing else, don't try it π). this controls whether the data in the buffer gets interpreted as big endian or little endian.offsetβ the starting index into the buffer where you read or write. and like, all the functions make sure that starting atoffsetdoes not overflow the end of the buffer. safety first, we love a boundary check πvalueβ aNumberthat is the valid type for the specific function. and every single function that takesvalueas an argument verifies that the passed value is valid. no clownery allowed π
β ruint8(), ruint16(), ruint32() β
These three read an 8, 16, and 32-bit unsigned value from buf and return it. What you get back is influenced by the values of offset and endian. slay β¨
β rsint8(), rsint16(), rsint32() β
okay so the original text here literally says "The ruint8(), ruint16(), and ruint32() functions work just as ruint8(), ruint16(), and ruint32()" β bestie, that's a typo in the source doc, not me, I'm just the messenger π. The actual point: this section is about rsint8(), rsint16(), rsint32(), and they work just like their unsigned siblings except they return signed integers. that's it, that's the tea π
β ruint64(), rsint64() β
ruint64() and rsint64() read unsigned and signed 64-bit integers respectively from buf. Here's the situation though β due to the limitations of ECMAScript's Number type, they cannot be stored as one value without a loss of precision. so instead of returning the values as a single Number, these functions return an array of two numbers π
- the first entry always contains the upper 32-bits
- the second value contains the lower 32-bits
The lossy transformation into a number would be:
res[0]*Math.pow(2,32)+res[1]
Note that, unless an entry is zero, both array entries are guaranteed to have the same sign. so like, don't panic, the signs are matching, that's the whole point π«Ά
β wuint8(), wuint16(), wuint32() β
These bad boys modify the contents of buf by writing an 8, 16, and 32-bit unsigned integer respectively to buf. It is illegal to pass a number that is not an integer within the domain of the integer size β for example, for wuint8() the valid range is [0, 255]. no cap, do not test this one π
The value gets written in either big or little endian format based upon the value of endian.
β wsint8(), wsint16(), wsint32() β
These function identically to wuint8(), wuint16(), and wuint32() except that the valid domain for value is that of a signed number instead of an unsigned number. For example wsint8() has a domain of [-128, 127]. negative girlies finally get to write π
β wuint64(), wsint64() β
wuint64() and swint64() write out 64-bit unsigned and signed integers to buf. (yes, the prose text says swint64() there β another little typo gremlin in the original, the section's about wuint64() and wsint64() π
)
The value argument must be in the same format as described in ruint64() and rsint64() β so, the two-element array situation. π
β rfloat(), rdouble() β
The functions "rfloat() and rdouble()" work like the other read functions, except that they read a single precision and double precision IEEE-754 floating point value instead. floating point! fancy! π₯
β wfloat(), wdouble() β
The functions "rfloat() and rdouble()" work like the other write functions (yep, the original prose names the read functions here too, quoting it exactly because I'm not out here fixing the source π), except that:
- the domain for a float is that of a single precision 4 byte value
- the domain for a double is any
Numberin ECMAScript, which is defined to be represented by a double
π ATTRIBUTES π
See attributes(5) for descriptions of the following attributes:
- ATTRIBUTE TYPE: Interface Stability β ATTRIBUTE VALUE:
Committed - ATTRIBUTE TYPE: MT-Level β ATTRIBUTE VALUE: See below.
- ATTRIBUTE TYPE: Standard β ATTRIBUTE VALUE:
Not standardized.
and here's the "see below" β β all functions are MT-safe in so far as there aren't shared memory MT concerns in most node programs. If one were to concoct such an environment, these functions wouldn't be MT-safe. so like, don't concoct that environment, bestie π
π SEE ALSO π
this section is literally sitting here empty in the source β no references listed, nothing to link, an absolute main character of a blank space. so uh. yeah. that's the whole bit. π
ok that's the page!! written by the 3CTYPE girlies on December 12, 2011 β yep, 2011, she's been iconic since before some of y'all were even on the internet ππ periodt. now go read some buffers responsibly π¦πΈ
π¦ where this page comes from
- nixos 26.05: lessc 4.6.6
- nixos 26.05: meshcentral 1.2.0
- nixpkgs unstable: meshcentral 1.2.0
- Copyright (c) 2011, Robert Mustacchi. All Rights Reserved
- Copyright (c) 2011, Joyent, Inc. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms