From 79412cefa0d333986c3d705186432fd04362d173 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sun, 8 Jul 2018 19:45:11 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Close=20file=20stream=20if=20end?= =?UTF-8?q?=20has=20been=20reached?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/streams/getFileFromDisks.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ssn/streams/getFileFromDisks.ts b/src/ssn/streams/getFileFromDisks.ts index 6ef0332..7371585 100644 --- a/src/ssn/streams/getFileFromDisks.ts +++ b/src/ssn/streams/getFileFromDisks.ts @@ -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