@@ -14,12 +14,13 @@ import {
14
14
FileSystemProviderInfo ,
15
15
FSCapabilities ,
16
16
FSCapabilityFlags ,
17
+ ReadFileOptions ,
17
18
UrlOrReference ,
18
19
VFileSystemCore ,
19
20
VfsDirEntry ,
20
21
VfsStat ,
21
22
} from '../VFileSystem.js' ;
22
- import { VFileSystemProvider , VProviderFileSystem } from '../VirtualFS.js' ;
23
+ import type { VFileSystemProvider , VProviderFileSystem } from '../VirtualFS.js' ;
23
24
24
25
export function cspellIOToFsProvider ( cspellIO : CSpellIO ) : VFileSystemProvider {
25
26
const capabilities = FSCapabilityFlags . Stat | FSCapabilityFlags . ReadWrite | FSCapabilityFlags . ReadDir ;
@@ -34,7 +35,7 @@ export function cspellIOToFsProvider(cspellIO: CSpellIO): VFileSystemProvider {
34
35
const fs : VProviderFileSystem = {
35
36
providerInfo : { name } ,
36
37
stat : ( url ) => cspellIO . getStat ( url ) ,
37
- readFile : ( url ) => cspellIO . readFile ( url ) ,
38
+ readFile : ( url , options ) => cspellIO . readFile ( url , options ) ,
38
39
readDirectory : ( url ) => cspellIO . readDirectory ( url ) ,
39
40
writeFile : ( file ) => cspellIO . writeFile ( file . url , file . content ) ,
40
41
dispose : ( ) => undefined ,
@@ -145,13 +146,17 @@ export class WrappedProviderFs implements VFileSystemCore {
145
146
}
146
147
}
147
148
148
- async readFile ( urlRef : UrlOrReference , encoding ?: BufferEncoding ) : Promise < TextFileResource > {
149
+ async readFile (
150
+ urlRef : UrlOrReference ,
151
+ optionsOrEncoding ?: BufferEncoding | ReadFileOptions ,
152
+ ) : Promise < TextFileResource > {
149
153
const traceID = performance . now ( ) ;
150
154
const url = urlOrReferenceToUrl ( urlRef ) ;
151
155
this . logEvent ( 'readFile' , 'start' , traceID , url ) ;
152
156
try {
153
157
checkCapabilityOrThrow ( this . fs , this . capabilities , FSCapabilityFlags . Read , 'readFile' , url ) ;
154
- return createTextFileResource ( await this . fs . readFile ( urlRef ) , encoding ) ;
158
+ const readOptions = toOptions ( optionsOrEncoding ) ;
159
+ return createTextFileResource ( await this . fs . readFile ( urlRef , readOptions ) , readOptions ?. encoding ) ;
155
160
} catch ( e ) {
156
161
this . logEvent ( 'readFile' , 'error' , traceID , url , e instanceof Error ? e . message : '' ) ;
157
162
throw wrapError ( e ) ;
@@ -282,3 +287,7 @@ export function chopUrl(url: URL | undefined): string {
282
287
export function rPad ( str : string , len : number , ch = ' ' ) : string {
283
288
return str . padEnd ( len , ch ) ;
284
289
}
290
+
291
+ function toOptions ( val : BufferEncoding | ReadFileOptions | undefined ) : ReadFileOptions | undefined {
292
+ return typeof val === 'string' ? { encoding : val } : val ;
293
+ }
0 commit comments