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",
|
"name": "ente",
|
||||||
"productName": "ente",
|
"productName": "ente",
|
||||||
"version": "1.5.1",
|
"version": "1.5.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Desktop client for ente.io",
|
"description": "Desktop client for ente.io",
|
||||||
"main": "app/main.js",
|
"main": "app/main.js",
|
||||||
|
|
|
@ -28,21 +28,27 @@ const getFileStream = async (filePath: string) => {
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
const readableStream = new ReadableStream<Uint8Array>({
|
const readableStream = new ReadableStream<Uint8Array>({
|
||||||
async pull(controller) {
|
async pull(controller) {
|
||||||
const buff = new Uint8Array(FILE_STREAM_CHUNK_SIZE);
|
try {
|
||||||
|
const buff = new Uint8Array(FILE_STREAM_CHUNK_SIZE);
|
||||||
|
|
||||||
// original types were not working correctly
|
// original types were not working correctly
|
||||||
const bytesRead = (await fs.read(
|
const bytesRead = (await fs.read(
|
||||||
file,
|
file,
|
||||||
buff,
|
buff,
|
||||||
0,
|
0,
|
||||||
FILE_STREAM_CHUNK_SIZE,
|
FILE_STREAM_CHUNK_SIZE,
|
||||||
offset
|
offset
|
||||||
)) as unknown as number;
|
)) as unknown as number;
|
||||||
offset += bytesRead;
|
offset += bytesRead;
|
||||||
if (bytesRead === 0) {
|
if (bytesRead === 0) {
|
||||||
controller.close();
|
controller.close();
|
||||||
} else {
|
await fs.close(file);
|
||||||
controller.enqueue(buff);
|
} else {
|
||||||
|
controller.enqueue(buff);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logError(e, 'stream pull failed');
|
||||||
|
await fs.close(file);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue