comparable-storable-types
read, write, and compare binary types
Use this module if you want uniform access for reading, writing, comparison, sizes, and minimum/maximum values for a bunch of different machine types.
This module was built specifically for implementing a range of types for spatial trees on disk.
example
write
var type =var f =var buf = 2fconsole
read
var type =var f =var x = fconsole
cmp
var type =var B =var bufs = 'zzz' 'qrs' '123' '100'bufsconsole
api
var types = require('comparable-storable-types')
var t = types(str)
Look up a type object t
by a description string str
.
Types are:
float
,float32
,f
,f32
double
,float64
,d
,f64
uint8
,ui8
,u8
uint16
,ui16
,u16
uint32
,ui32
,u32
sint8
,int8
,si8
,i8
,s8
sint16
,int16
,si16
,i16
,s16
sint32
,int32
,si32
,i32
,s32
var value = t.read(buf, offset)
Parse the value for the type at offset
in buf
.
t.write(buf, value, offset)
Write value
into buf
at offset
.
t.size
Size in bytes of the type
t.min
Minimum value for the type
t.max
Maximum value for the type
t.cmp
Comparison operators:
t.cmp.eq(a, b)
t.cmp.lt(a, b)
t.cmp.lte(a, b)
t.cmp.gt(a, b)
t.cmp.gte(a, b)
install
npm install comparable-storable-types
license
BSD