Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Created September 18, 2012 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TooTallNate/00241b86d7f6a874b933 to your computer and use it in GitHub Desktop.
Save TooTallNate/00241b86d7f6a874b933 to your computer and use it in GitHub Desktop.
// sometimes you get a variable length array that is terminated by a NULL byte.
var buf = new Buffer(int.size * 3)
int.set(buf, int.size * 0, 5)
int.set(buf, int.size * 1, 8)
int.set(buf, int.size * 2, 0) // <- terminate with 0s
// you can create an array instance with the length automatically determined
var array = IntArray.untilZero(buf)
console.log(array.length)
// 2
console.log(array)
// [ 5, 8 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment