Skip to content

Instantly share code, notes, and snippets.

@kanreisa
Last active December 24, 2015 05:59
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 kanreisa/6753982 to your computer and use it in GitHub Desktop.
Save kanreisa/6753982 to your computer and use it in GitHub Desktop.
var packet = null;
var testStream = fs.createReadStream(__dirname + '/test.m2ts');
testStream.on('data', function (chunk) {
var i, l;
for (i = 0, l = chunk.length; i < l; i++) {
if (chunk[i] === 0x47 && (packet === null || packet.length >= 188)) {
if (packet !== null) {
console.log(packet.join(' '));
}
packet = [];
console.log('#' + i, '<- sync_byte');
}
if (packet !== null) {
packet.push(chunk[i]);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment