Fix type errors in fs.ts

This commit is contained in:
Manav Rathi 2024-03-22 20:01:02 +05:30
parent 6c8f4185f7
commit 0fdb2fb357
No known key found for this signature in database

View file

@ -25,16 +25,14 @@ export const getDirFilePaths = async (dirPath: string) => {
return files;
};
export const getFileStream = async (filePath: string) => {
const getFileStream = async (filePath: string) => {
const file = await fs.open(filePath, "r");
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
const bytesRead = (await fs.read(
file,
const bytesRead = (await file.read(
buff,
0,
FILE_STREAM_CHUNK_SIZE,
@ -43,16 +41,16 @@ export const getFileStream = async (filePath: string) => {
offset += bytesRead;
if (bytesRead === 0) {
controller.close();
await fs.close(file);
await file.close();
} else {
controller.enqueue(buff.slice(0, bytesRead));
}
} catch (e) {
await fs.close(file);
await file.close();
}
},
async cancel() {
await fs.close(file);
await file.close();
},
});
return readableStream;