read, write, and compare binary types
npm install comparable-storable-typesread, 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.
`` js`
var type = require('comparable-storable-types')
var f = type('uint16')
var buf = new Buffer(2)
f.write(buf, 5555, 0)
console.log(buf.toString('hex'))
` js`
var type = require('comparable-storable-types')
var f = type('float32')
var x = f.read(Buffer([ 0x40, 0x49, 0x0f, 0xdb ]), 0)
console.log(x)
` js`
var type = require('comparable-storable-types')
var B = type('buffer[3]')
var bufs = [ 'zzz', 'qrs', '123', '100' ].map(Buffer)
bufs.sort(function (a, b) { return B.cmp.lt(a, b) ? -1 : 1 })
console.log(bufs.map(String))
``
var types = require('comparable-storable-types')
Look up a type object t by a description string str.
Types are:
* float, float32, f, f32double
* , float64, d, f64uint8
* , ui8, u8uint16
* , ui16, u16uint32
* , ui32, u32sint8
* , int8, si8, i8, s8sint16
* , int16, si16, i16, s16sint32
* , int32, si32, i32, s32
Parse the value for the type at offset in buf.
Write value into buf at offset.
Size in bytes of the type
Minimum value for the type
Maximum value for the type
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)
*
```
npm install comparable-storable-types
BSD