Skip to content

Commit 70454d1

Browse files
[readFile]: compatible like node:fs
1 parent 68c953b commit 70454d1

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ declare module '@isomorphic-git/lightning-fs' {
4747

4848
writeFile(filepath: string, data: Uint8Array | string, options: FS.WriteFileOptions | undefined | string, cb: (err: Error) => void): void
4949

50-
readFile(filepath: string, options: FS.ReadFileOptions | undefined | string, cb: (err: Error, data: Uint8Array | string) => void): void
50+
readFile(filepath: string, options: 'utf8' | { encoding: 'utf8' }, cb: (err: Error, data: string) => void): void
51+
readFile(filepath: string, options: {} | void, cb: (err: Error, data: Uint8Array) => void): void
5152

5253
/**
5354
* Delete a file
@@ -149,7 +150,7 @@ declare module '@isomorphic-git/lightning-fs' {
149150

150151
writeFile(filepath: string, data: Uint8Array | string, options?: FS.WriteFileOptions | string): Promise<void>
151152

152-
readFile(filepath: string, options: { encoding: 'utf8' }): Promise<string>
153+
readFile(filepath: string, options: 'utf8' | { encoding: 'utf8' }): Promise<string>
153154
readFile(filepath: string, options?: {}): Promise<Uint8Array>
154155

155156
/**

src/DefaultBackend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports = class DefaultBackend {
9595
return this._cache.writeStat(filepath, size, opts)
9696
}
9797
async readFile(filepath, opts) {
98-
const { encoding } = opts;
98+
const encoding = typeof opts === "string" ? opts : opts?.encoding;
9999
if (encoding && encoding !== 'utf8') throw new Error('Only "utf8" encoding is supported in readFile');
100100
let data = null, stat = null
101101
try {

0 commit comments

Comments
 (0)