|
1 | 1 | import * as pathModule from 'path'; |
2 | 2 | import { Node, Link, File } from './node'; |
3 | | -import Stats from './Stats'; |
| 3 | +import Stats, { TStatNumber } from './Stats'; |
4 | 4 | import Dirent from './Dirent'; |
5 | 5 | import { Buffer } from 'buffer'; |
6 | 6 | import setImmediate from './setImmediate'; |
@@ -357,6 +357,20 @@ const readdirDefaults: IReaddirOptions = { |
357 | 357 | const getReaddirOptions = optsGenerator<IReaddirOptions>(readdirDefaults); |
358 | 358 | const getReaddirOptsAndCb = optsAndCbGenerator<IReaddirOptions, TDataOut[] | Dirent[]>(getReaddirOptions); |
359 | 359 |
|
| 360 | +// Options for `fs.fstat`, `fs.fstatSync`, `fs.lstat`, `fs.lstatSync`, `fs.stat`, and `fs.statSync` |
| 361 | +export interface IStatOptions { |
| 362 | + bigint?: boolean; |
| 363 | +} |
| 364 | +const statDefaults: IStatOptions = { |
| 365 | + bigint: false, |
| 366 | +}; |
| 367 | +const getStatOptions: (options?: any) => IStatOptions = (options = {}) => extend({}, statDefaults, options); |
| 368 | +const getStatOptsAndCb: (options: any, callback?: TCallback<Stats>) => [IStatOptions, TCallback<Stats>] = ( |
| 369 | + options, |
| 370 | + callback?, |
| 371 | +) => |
| 372 | + typeof options === 'function' ? [getStatOptions(), options] : [getStatOptions(options), validateCallback(callback)]; |
| 373 | + |
360 | 374 | // ---------------------------------------- Utility functions |
361 | 375 |
|
362 | 376 | function getPathFromURLPosix(url): string { |
@@ -1416,51 +1430,60 @@ export class Volume { |
1416 | 1430 | this.wrapAsync(this.realpathBase, [pathFilename, opts.encoding], callback); |
1417 | 1431 | } |
1418 | 1432 |
|
1419 | | - private lstatBase(filename: string): Stats { |
| 1433 | + private lstatBase(filename: string, bigint: boolean = false): Stats { |
1420 | 1434 | const link: Link = this.getLink(filenameToSteps(filename)); |
1421 | 1435 | if (!link) throwError(ENOENT, 'lstat', filename); |
1422 | | - return Stats.build(link.getNode()); |
| 1436 | + return Stats.build(link.getNode(), bigint); |
1423 | 1437 | } |
1424 | 1438 |
|
1425 | | - lstatSync(path: TFilePath): Stats { |
1426 | | - return this.lstatBase(pathToFilename(path)); |
| 1439 | + lstatSync(path: TFilePath, options?: IStatOptions): Stats { |
| 1440 | + return this.lstatBase(pathToFilename(path), getStatOptions(options).bigint); |
1427 | 1441 | } |
1428 | 1442 |
|
1429 | | - lstat(path: TFilePath, callback: TCallback<Stats>) { |
1430 | | - this.wrapAsync(this.lstatBase, [pathToFilename(path)], callback); |
| 1443 | + lstat(path: TFilePath, callback: TCallback<Stats>); |
| 1444 | + lstat(path: TFilePath, options: IStatOptions, callback: TCallback<Stats>); |
| 1445 | + lstat(path: TFilePath, a: TCallback<Stats> | IStatOptions, b?: TCallback<Stats>) { |
| 1446 | + const [opts, callback] = getStatOptsAndCb(a, b); |
| 1447 | + this.wrapAsync(this.lstatBase, [pathToFilename(path), opts.bigint], callback); |
1431 | 1448 | } |
1432 | 1449 |
|
1433 | | - private statBase(filename: string): Stats { |
| 1450 | + private statBase(filename: string, bigint: boolean = false): Stats { |
1434 | 1451 | let link: Link = this.getLink(filenameToSteps(filename)); |
1435 | 1452 | if (!link) throwError(ENOENT, 'stat', filename); |
1436 | 1453 |
|
1437 | 1454 | // Resolve symlinks. |
1438 | 1455 | link = this.resolveSymlinks(link); |
1439 | 1456 | if (!link) throwError(ENOENT, 'stat', filename); |
1440 | 1457 |
|
1441 | | - return Stats.build(link.getNode()); |
| 1458 | + return Stats.build(link.getNode(), bigint); |
1442 | 1459 | } |
1443 | 1460 |
|
1444 | | - statSync(path: TFilePath): Stats { |
1445 | | - return this.statBase(pathToFilename(path)); |
| 1461 | + statSync(path: TFilePath, options?: IStatOptions): Stats { |
| 1462 | + return this.statBase(pathToFilename(path), getStatOptions(options).bigint); |
1446 | 1463 | } |
1447 | 1464 |
|
1448 | | - stat(path: TFilePath, callback: TCallback<Stats>) { |
1449 | | - this.wrapAsync(this.statBase, [pathToFilename(path)], callback); |
| 1465 | + stat(path: TFilePath, callback: TCallback<Stats>); |
| 1466 | + stat(path: TFilePath, options: IStatOptions, callback: TCallback<Stats>); |
| 1467 | + stat(path: TFilePath, a: TCallback<Stats> | IStatOptions, b?: TCallback<Stats>) { |
| 1468 | + const [opts, callback] = getStatOptsAndCb(a, b); |
| 1469 | + this.wrapAsync(this.statBase, [pathToFilename(path), opts.bigint], callback); |
1450 | 1470 | } |
1451 | 1471 |
|
1452 | | - private fstatBase(fd: number): Stats { |
| 1472 | + private fstatBase(fd: number, bigint: boolean = false): Stats { |
1453 | 1473 | const file = this.getFileByFd(fd); |
1454 | 1474 | if (!file) throwError(EBADF, 'fstat'); |
1455 | | - return Stats.build(file.node); |
| 1475 | + return Stats.build(file.node, bigint); |
1456 | 1476 | } |
1457 | 1477 |
|
1458 | | - fstatSync(fd: number): Stats { |
1459 | | - return this.fstatBase(fd); |
| 1478 | + fstatSync(fd: number, options?: IStatOptions): Stats { |
| 1479 | + return this.fstatBase(fd, getStatOptions(options).bigint); |
1460 | 1480 | } |
1461 | 1481 |
|
1462 | | - fstat(fd: number, callback: TCallback<Stats>) { |
1463 | | - this.wrapAsync(this.fstatBase, [fd], callback); |
| 1482 | + fstat(fd: number, callback: TCallback<Stats>); |
| 1483 | + fstat(fd: number, options: IStatOptions, callback: TCallback<Stats>); |
| 1484 | + fstat(fd: number, a: TCallback<Stats> | IStatOptions, b?: TCallback<Stats>) { |
| 1485 | + const [opts, callback] = getStatOptsAndCb(a, b); |
| 1486 | + this.wrapAsync(this.fstatBase, [fd, opts.bigint], callback); |
1464 | 1487 | } |
1465 | 1488 |
|
1466 | 1489 | private renameBase(oldPathFilename: string, newPathFilename: string) { |
|
0 commit comments