Skip to content

Instantly share code, notes, and snippets.

@eastlondoner
Last active July 22, 2016 21:35
Show Gist options
  • Save eastlondoner/26910b28943235162f4b9504d06ad6ab to your computer and use it in GitHub Desktop.
Save eastlondoner/26910b28943235162f4b9504d06ad6ab to your computer and use it in GitHub Desktop.
make a float 32 array and save it to disk
fs = require 'fs'
toFloatArray = (list) ->
buffer = new ArrayBuffer(4 * list.length)
dataView = new DataView buffer
offset = 0
addNextValue = (value) ->
dataView.setFloat32 offset, value, true
offset += 4
addNextValue val for val in list
return new Buffer(buffer)
example = [-2.56, 999999999999999, 1.0001]
wstream = fs.createWriteStream 'myFile.bin'
try
wstream.write(toFloatArray example);
finally
wstream.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment