Last active
July 22, 2016 21:35
-
-
Save eastlondoner/26910b28943235162f4b9504d06ad6ab to your computer and use it in GitHub Desktop.
make a float 32 array and save it to disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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