Merge pull request #39 from ente-io/too-many-files
Close file when streaming done
This commit is contained in:
commit
9b7fa381cb
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "ente",
|
||||
"productName": "ente",
|
||||
"version": "1.5.1",
|
||||
"version": "1.5.2",
|
||||
"private": true,
|
||||
"description": "Desktop client for ente.io",
|
||||
"main": "app/main.js",
|
||||
|
|
|
@ -28,6 +28,7 @@ const getFileStream = async (filePath: string) => {
|
|||
let offset = 0;
|
||||
const readableStream = new ReadableStream<Uint8Array>({
|
||||
async pull(controller) {
|
||||
try {
|
||||
const buff = new Uint8Array(FILE_STREAM_CHUNK_SIZE);
|
||||
|
||||
// original types were not working correctly
|
||||
|
@ -41,9 +42,14 @@ const getFileStream = async (filePath: string) => {
|
|||
offset += bytesRead;
|
||||
if (bytesRead === 0) {
|
||||
controller.close();
|
||||
await fs.close(file);
|
||||
} else {
|
||||
controller.enqueue(buff);
|
||||
}
|
||||
} catch (e) {
|
||||
logError(e, 'stream pull failed');
|
||||
await fs.close(file);
|
||||
}
|
||||
},
|
||||
});
|
||||
return readableStream;
|
||||
|
|
Loading…
Reference in a new issue