Create C typed "array" instances on top of Buffers
This module offers an "array" implementation on top of Node.js Buffers using the ref "type" interface.
$ npm install ref-array
var ref =var ArrayType =// typedefvar int = reftypesint// define the "int" typevar IntArray =// now we can create array instances; the constructor takes the same arguments// the native JS Array classvar a = 5 // by lengthalength // 5a0 = 0a1 = 1a2 = -1a3 = 2a4 = -2var b = 1 2 3 4 5 // with an existing Arrayblength // 5b0 // 1b1 // 2b2 // 3b3 // 4b4 // 5
// sometimes you get a variable length array that is terminated by a NULL byte.var buf = intsize * 3intintint // <- terminate with 0s// you can create an array instance with the length automatically determinedvar array = IntArrayconsole// 2console// [ 5, 8 ]
var ffi =// the "int" type may be used as a "type" in FFI'd functions or callbacksvar func = ffivar arg = 3arg0 = 1234arg1 = -9999arg2 = 1var rtn =
(The MIT License)
Copyright (c) 2012 Nathan Rajlich <firstname.lastname@example.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.