cleaned code up a bit

This commit is contained in:
uh wot 2022-03-09 23:19:08 +01:00
parent 83c0b9a106
commit 4ce782e6b5
Signed by: uhwot
GPG Key ID: CB2454984587B781
2 changed files with 11 additions and 11 deletions

2
dist/worker.js vendored

File diff suppressed because one or more lines are too long

View File

@ -423,19 +423,15 @@ async function track(id, format, tagging, range_header) {
async function pipeDecryptedStream(writer, body, length, cipher, fixed_range_start, bytes_remove_start, bytes_remove_end) { async function pipeDecryptedStream(writer, body, length, cipher, fixed_range_start, bytes_remove_start, bytes_remove_end) {
const reader = body.getReader({ mode: 'byob' }) const reader = body.getReader({ mode: 'byob' })
let byte_count = fixed_range_start let byte_count = fixed_range_start
let buffer = new Uint8Array(2048)
let end = false let end = false
while (!end) { while (!end) {
end = byte_count + 2048 >= length end = byte_count + 2048 >= length
let min_bytes
if (!end) {
min_bytes = 2048
} else {
min_bytes = length - byte_count
}
let chunk = (await reader.readAtLeast(min_bytes, new Uint8Array(2048))).value let chunk = (await reader.readAtLeast(2048, buffer)).value
if (byte_count % 6144 === 0 && min_bytes == 2048) { if (byte_count % 6144 === 0 && chunk.byteLength == 2048) {
// encrypted chunk // encrypted chunk
cipher.decrypt_chunk(chunk) cipher.decrypt_chunk(chunk)
} }
@ -445,11 +441,15 @@ async function pipeDecryptedStream(writer, body, length, cipher, fixed_range_sta
bytes_remove_start = 0 bytes_remove_start = 0
} }
if (end && bytes_remove_end !== 0) { if (end && bytes_remove_end !== 0) {
chunk = chunk.slice(0, chunk.length - bytes_remove_end) chunk = chunk.slice(0, chunk.byteLength - bytes_remove_end)
} }
byte_count += 2048
await writer.write(chunk) await writer.write(chunk)
if (!end) {
byte_count += 2048
buffer = new Uint8Array(chunk.buffer);
}
} }
writer.close() writer.close()