This commit is contained in:
2026-10-17 18:14:31 +07:00
parent 1c42ae2a75
commit 701bca234e
31 changed files with 9774 additions and 21 deletions
+20
View File
@@ -0,0 +1,20 @@
export function parseRange(
header: string | null,
size: number,
): { start: number; end: number } | null {
if (!Number.isSafeInteger(size) || size <= 0) return null
if (header === null) return { start: 0, end: size - 1 }
const match = /^bytes=(\d*)-(\d*)$/.exec(header)
if (!match || (!match[1] && !match[2])) return null
const start = match[1] ? Number(match[1]) : Math.max(0, size - Number(match[2]))
const end = match[1] && match[2] ? Math.min(Number(match[2]), size - 1) : size - 1
if (
!Number.isSafeInteger(start) ||
!Number.isSafeInteger(end) ||
start > end ||
start >= size ||
end < 0
)
return null
return { start, end }
}