Skip to content

Commit 71d6aa1

Browse files
authored
sdk/typescript: Improve FileSystem.readFile() compatibility (#79)
Improve readFile() compatibility with Node filesystem API.
2 parents 49d0651 + fd112dc commit 71d6aa1

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

sdk/typescript/src/filesystem.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,15 @@ export class Filesystem {
349349
await updateStmt.run(buffer.length, now, ino);
350350
}
351351

352-
async readFile(path: string, encoding?: BufferEncoding): Promise<Buffer | string> {
352+
async readFile(
353+
path: string,
354+
options?: BufferEncoding | { encoding?: BufferEncoding }
355+
): Promise<Buffer | string> {
356+
// Normalize options
357+
const encoding = typeof options === 'string'
358+
? options
359+
: options?.encoding;
360+
353361
const ino = await this.resolvePath(path);
354362
if (ino === null) {
355363
throw new Error(`ENOENT: no such file or directory, open '${path}'`);

0 commit comments

Comments
 (0)