cleaned code up a bit
This commit is contained in:
parent
83c0b9a106
commit
4ce782e6b5
File diff suppressed because one or more lines are too long
20
index.js
20
index.js
|
@ -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) {
|
||||
const reader = body.getReader({ mode: 'byob' })
|
||||
let byte_count = fixed_range_start
|
||||
|
||||
let buffer = new Uint8Array(2048)
|
||||
let end = false
|
||||
while (!end) {
|
||||
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
|
||||
cipher.decrypt_chunk(chunk)
|
||||
}
|
||||
|
@ -445,11 +441,15 @@ async function pipeDecryptedStream(writer, body, length, cipher, fixed_range_sta
|
|||
bytes_remove_start = 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)
|
||||
|
||||
if (!end) {
|
||||
byte_count += 2048
|
||||
buffer = new Uint8Array(chunk.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
writer.close()
|
||||
|
|
Loading…
Reference in New Issue