Read large payload

This commit is contained in:
Belma Gutlic
2019-12-24 20:36:16 +01:00
parent a5ec8efd28
commit 4b2091be9f
2 changed files with 13 additions and 3 deletions

View File

@ -35,8 +35,17 @@ export function decryptStream(handshake: Handshake): ReturnEncryptionWrapper {
return async function * (source) {
for await (const chunk of source) {
const chunkBuffer = Buffer.from(chunk);
const decrypted = await handshake.decrypt(chunkBuffer, handshake.session);
yield decrypted
for (let i = 0; i < chunkBuffer.length; i += maxPlaintextLength) {
let end = i + maxPlaintextLength;
if (end > chunkBuffer.length) {
end = chunkBuffer.length;
}
const chunk = chunkBuffer.slice(i, end);
const decrypted = await handshake.decrypt(chunk, handshake.session);
yield decrypted;
}
}
}
}