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