11import { Readable } from 'stream' ;
22import createDebug from 'debug' ;
3- import { Stats , createReadStream } from 'fs' ;
4- import { fstat , open } from 'fs-extra' ;
3+ import { Stats , createReadStream , promises as fsPromises } from 'fs' ;
54import { GetUriProtocol } from './' ;
65import NotFoundError from './notfound' ;
76import NotModifiedError from './notmodified' ;
@@ -42,11 +41,12 @@ export const file: GetUriProtocol<FileOptions> = async (
4241
4342 // `open()` first to get a file descriptor and ensure that the file
4443 // exists.
45- const fd = await open ( filepath , flags , mode ) ;
44+ const fdHandle = await fsPromises . open ( filepath , flags , mode ) ;
45+ // extract the numeric file descriptor
46+ const fd = fdHandle . fd ;
4647
47- // Now `fstat()` to check the `mtime` and store the stat object for
48- // the cache.
49- const stat = await fstat ( fd ) ;
48+ // store the stat object for the cache.
49+ const stat = await fdHandle . stat ( ) ;
5050
5151 // if a `cache` was provided, check if the file has not been modified
5252 if ( cache && cache . stat && stat && isNotModified ( cache . stat , stat ) ) {
@@ -55,8 +55,7 @@ export const file: GetUriProtocol<FileOptions> = async (
5555
5656 // `fs.ReadStream` takes care of calling `fs.close()` on the
5757 // fd after it's done reading
58- // @ts -expect-error `@types/node` doesn't allow `null` as file path :/
59- const rs = createReadStream ( null , {
58+ const rs = createReadStream ( filepath , {
6059 autoClose : true ,
6160 ...opts ,
6261 fd,
0 commit comments