Created
January 31, 2018 23:23
-
-
Save steve-taylor/f779725f9296a378fabbcd9f3c87d963 to your computer and use it in GitHub Desktop.
BIF file parser
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
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