Last active
April 11, 2019 00:31
-
-
Save evert/d7fdee2843c5267a5161f07594b4ca3a to your computer and use it in GitHub Desktop.
This file contains 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
async () => { | |
const response = await fetch('large.bin'); | |
const buffer = await response.arrayBuffer(); | |
}; |
This file contains 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
const fs = require('fs'); | |
const input = 'large.json'; | |
const output = 'large.bin'; | |
console.log('Reading %s', input); | |
const buffer = fs.readFileSync(input); | |
const json = JSON.parse(buffer); | |
console.log('Writing %s', output); | |
const outBuffer = new Int8Array(json.data.length); | |
let index = 0; | |
for(const item of json.data) { | |
// Input is between -1 and 1. This converts that float into a number between | |
// 1 and 255 inclusive. | |
const newValue = Math.floor((item * 127) + 128); | |
outBuffer[index] = newValue; | |
index++; | |
} | |
fs.writeFileSync(output, outBuffer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment