Skip to content

Instantly share code, notes, and snippets.

@steve-taylor
Created January 31, 2018 23:23
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 steve-taylor/f779725f9296a378fabbcd9f3c87d963 to your computer and use it in GitHub Desktop.
Save steve-taylor/f779725f9296a378fabbcd9f3c87d963 to your computer and use it in GitHub Desktop.
BIF file parser
function *parseBif(buffer) {
const data = new DataView(buffer);
// Ensure this is a BIF v0.
if (data.getUint32(0, true) !== 0x46494289 || data.getUint32(4, true) !== 0x0a1a0a0d || data.getUint32(8, true) !== 0) {
return;
}
const separation = data.getUint32(16, true) || 1000;
const start = 64;
const end = start + (data.getUint32(12, true) << 3);
for (i = start; i < end; i += 8) {
yield {
seconds: (data.getUint32(i, true) * separation) / 1000,
bytes: buffer.slice(data.getUint32(i + 4, true), data.getUint32(i + 12, true))
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment