🐛 Close file stream if end has been reached
This commit is contained in:
parent
03128a2920
commit
79412cefa0
1 changed files with 3 additions and 2 deletions
|
@ -33,12 +33,13 @@ export default async function getFileFromDisks(disks: string[], { diskStart, off
|
||||||
//We can still write the whole chunk before ending the stream
|
//We can still write the whole chunk before ending the stream
|
||||||
if (readTooManyBytes === 0) {
|
if (readTooManyBytes === 0) {
|
||||||
outputStream.end(chunk);
|
outputStream.end(chunk);
|
||||||
|
curDisk.close();
|
||||||
} else {
|
} else {
|
||||||
//We must shorten the chunk, write the shortened chunk and then end the stream
|
//We must shorten the chunk, write the shortened chunk and then end the stream
|
||||||
const shortenedLength = chunk.length - readTooManyBytes;
|
const shortenedLength = chunk.length - readTooManyBytes;
|
||||||
const shortenedChunk = new Buffer(shortenedLength);
|
const shortenedChunk = Buffer.alloc(shortenedLength, chunk);
|
||||||
shortenedChunk.fill(chunk, 0, shortenedLength);
|
|
||||||
outputStream.end(shortenedChunk);
|
outputStream.end(shortenedChunk);
|
||||||
|
curDisk.close();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//Nowhere near the end, so just write normally
|
//Nowhere near the end, so just write normally
|
||||||
|
|
Loading…
Reference in a new issue