File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change 1+ import { URL } from 'url' ;
12import { Link , Node , Stats , Dirent } from "../node" ;
23import { Volume , filenameToSteps , StatWatcher } from "../volume" ;
34
4-
55describe ( 'volume' , ( ) => {
66 describe ( 'filenameToSteps(filename): string[]' , ( ) => {
77 it ( '/ -> []' , ( ) => {
@@ -432,6 +432,10 @@ describe('volume', () => {
432432 expect ( buf ) . toBeInstanceOf ( Buffer ) ;
433433 expect ( str ) . toBe ( data ) ;
434434 } ) ;
435+ it ( 'Read file with path passed as URL' , ( ) => {
436+ const str = vol . readFileSync ( new URL ( 'file:///text.txt' ) ) . toString ( ) ;
437+ expect ( str ) . toBe ( data ) ;
438+ } ) ;
435439 it ( 'Specify encoding as string' , ( ) => {
436440 const str = vol . readFileSync ( '/text.txt' , 'utf8' ) ;
437441 expect ( str ) . toBe ( data ) ;
Original file line number Diff line number Diff line change @@ -1018,13 +1018,14 @@ export class Volume {
10181018 private readFileBase ( id : TFileId , flagsNum : number , encoding : TEncoding ) : Buffer | string {
10191019 let result : Buffer | string ;
10201020
1021- const userOwnsFd = isFd ( id ) ;
1021+ const isUserFd = typeof id === 'number' ;
1022+ let userOwnsFd : boolean = isUserFd && isFd ( id ) ;
10221023 let fd : number ;
10231024
1024- if ( userOwnsFd ) {
1025- fd = id as number ;
1026- } else {
1027- const steps = filenameToSteps ( id as string ) ;
1025+ if ( userOwnsFd ) fd = id as number ;
1026+ else {
1027+ const filename = pathToFilename ( id as TFilePath ) ;
1028+ const steps = filenameToSteps ( filename ) ;
10281029 const link : Link = this . getResolvedLink ( steps ) ;
10291030
10301031 if ( link ) {
You can’t perform that action at this time.
0 commit comments