fix: Microscopy bulkdata and image retrieve (#3894)
This commit is contained in:
1 parent
7014e6ca4a
commit
7fac49b449
6 files changed
+187
-12
No files matched your search
@@ -0,0 +1,47 @@
|
||||
function checkToken(token, data, dataOffset): boolean {
|
||||
if (dataOffset + token.length > data.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let endIndex = dataOffset;
|
||||
|
||||
for (let i = 0; i < token.length; i++) {
|
||||
if (token[i] !== data[endIndex++]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function stringToUint8Array(str: string): Uint8Array {
|
||||
const uint = new Uint8Array(str.length);
|
||||
|
||||
for (let i = 0, j = str.length; i < j; i++) {
|
||||
uint[i] = str.charCodeAt(i);
|
||||
}
|
||||
|
||||
return uint;
|
||||
}
|
||||
|
||||
function findIndexOfString(
|
||||
data: Uint8Array,
|
||||
str: string,
|
||||
offset?: number
|
||||
): number {
|
||||
offset = offset || 0;
|
||||
|
||||
const token = stringToUint8Array(str);
|
||||
|
||||
for (let i = offset; i < data.length; i++) {
|
||||
if (token[0] === data[i]) {
|
||||
// console.log('match @', i);
|
||||
if (checkToken(token, data, i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
export default findIndexOfString;
|
||||
Reference in new issue
Block a user