Here's my logic to seek through a file inside a binary:
blob.arrayBuffer().then(arrayBuffer => {
const uint8Array = new Uint8Array(arrayBuffer);
for (let start = 0; start <= uint8Array.byteLength; start++) {
if ((uint8Array[start] & 0xff) === 0xff &&
(uint8Array[start + 1] & 0xff) === 0xd8 &&
(uint8Array[start + 2] & 0xff) === 0xff &&
(uint8Array[start + 3] & 0xff) === 0xe0 &&
1) {
// Found start of file
for (let i = start; i <= (uint8Array.byteLength - start); i++) {
if ((uint8Array[i] & 0xff) === 0xff &&
(uint8Array[i + 1] & 0xff) === 0xd9 &&
1) {
// Found ending of file
const offsetIdx = start;
const endIdx = (i + 1);
process(offsetIdx, endIdx);
break;
}
}
}
}
});
The above code searches files inside a binary by looking for the indexes (start, ending markers). The question is what is the fastest way to get the start and end index of a files inside a binary file? Or this this algorithm I have is the fastest one possible already?