I have a table that I am trying to read in Javascript, with data that is large enough that I would like to have it in binary format to save space. Most of the table is either numbers or enums, but there is some data that is strings. I'm trying to figure out the best way to read in that data in Javascript. Any suggestions?
FYI, the zipped up text version is ~33 MB, while the zipped up binary fine is ~20 MB, which is why I am trying to reduce the size, hopefully allowing it to load faster. I'm planning on doing some preprocessing of the data with Python, which will reduce the data to just that which I actually care about. I may be doing some filtering of this data, but ideally I would ultimately like a static website, so I would strongly prefer to not have to rely on server side code of any kind. The file that has almost anything of note is only ~1 MB, so not a huge concern I hope.
Bonus points if whatever system allows for a 16 bit float, as there are a number of floats that 16 bits is more than enough precision to capture adequately.
My code, simple as it is thus far, is as follows. Note the missing block where anything useful happens...
function loadBinaryFloatArray(url) {
var mRequest = new XMLHttpRequest();
mRequest.open('GET', url);
mRequest.responseType = 'arraybuffer';
mRequest.onreadystatechange = function () {
if (this.readyState === 4) {
}
};
mRequest.send();
}
console.log("Test")
loadBinaryFloatArray("/data/sbdb_important.bin")
The data looks something like this. Note I will probably be removing some of these columns, but this is the source data. Of some reference, only the first column actually will be stored as a string, the others can be stored as numbers of some kind or enumerations converted to a number. There will probably be two actual strings, I think I'm going to divide up the one string in to its two pieces.
For reference, the Python code to pack is as follows. I can change the e
s to something else if required, either float32s or an integer that converts to a decimal, but it would be nice to natively support.
struct.pack('ehifeefff',diameter,type,epoch,a,e,i,om,w,ma)