🐛 Close file stream if end has been reached

This commit is contained in:
C-3PO 2018-07-08 19:45:11 +02:00
parent 03128a2920
commit 79412cefa0
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -33,12 +33,13 @@ export default async function getFileFromDisks(disks: string[], { diskStart, off
//We can still write the whole chunk before ending the stream
if (readTooManyBytes === 0) {
outputStream.end(chunk);
curDisk.close();
} else {
//We must shorten the chunk, write the shortened chunk and then end the stream
const shortenedLength = chunk.length - readTooManyBytes;
const shortenedChunk = new Buffer(shortenedLength);
shortenedChunk.fill(chunk, 0, shortenedLength);
const shortenedChunk = Buffer.alloc(shortenedLength, chunk);
outputStream.end(shortenedChunk);
curDisk.close();
}
} else {
//Nowhere near the end, so just write normally