Code review fixes

This commit is contained in:
Vanilagy
2026-04-16 17:43:12 +02:00
parent aadfa77489
commit b85ecd3109
13 changed files with 253 additions and 44 deletions
+20 -10
View File
@@ -13,23 +13,33 @@ export const readNextMp3FrameHeader = async (reader: Reader, startPos: number, u
header: Mp3FrameHeader;
startPos: number;
} | null> => {
const CHUNK_SIZE = 2 ** 16; // So we don't need to grab thousands of slices
let currentPos = startPos;
// todo optimize this shit wtf is this
while (until === null || currentPos < until) {
let slice = reader.requestSlice(currentPos, FRAME_HEADER_SIZE);
const maxLength = until !== null
? Math.min(CHUNK_SIZE, until - currentPos)
: CHUNK_SIZE;
let slice = reader.requestSliceRange(currentPos, FRAME_HEADER_SIZE, maxLength);
if (slice instanceof Promise) slice = await slice;
if (!slice) break;
if (!slice || slice.length < FRAME_HEADER_SIZE) break;
const word = readU32Be(slice);
while (slice.remainingLength >= FRAME_HEADER_SIZE) {
const posBeforeRead = slice.filePos;
const word = readU32Be(slice);
const remainingBytes = reader.fileSize !== null
? reader.fileSize - currentPos
: null;
const result = readMp3FrameHeader(word, reader.fileSize !== null ? reader.fileSize - currentPos : null);
if (result.header) {
return { header: result.header, startPos: currentPos };
const result = readMp3FrameHeader(word, remainingBytes);
if (result.header) {
return { header: result.header, startPos: currentPos };
}
slice.filePos = posBeforeRead + result.bytesAdvanced;
currentPos = slice.filePos;
}
currentPos += result.bytesAdvanced;
}
return null;