Skip to content

Latest commit

 

History

History
221 lines (149 loc) · 4.21 KB

File metadata and controls

221 lines (149 loc) · 4.21 KB

Stat

Get full details on a file or directory.

Usage

var stat = require( '@stdlib/fs/stat' );

stat( path, clbk )

Asynchronously returns file system statistics for a file or directory.

The callback is invoked with an fs.Stats object containing methods and values describing the target path.

stat( 'package.json', onStat );

function onStat( error, stats ) {
    if ( error ) {
        throw error;
    }
    console.log( stats );
}

stat( path, options, clbk )

Asynchronously returns file system statistics for a file or directory with options.

stat( 'package.json', {
    'bigint': true
}, onStat );

function onStat( error, stats ) {
    if ( error ) {
        throw error;
    }
    console.log( stats );
}

Options:

  • bigint: boolean flag indicating whether numeric values should be returned as bigint. Default: false.
stat( 'package.json', onStat );

function onStat( error, stats ) {
    if ( error ) {
        throw error;
    }
    console.log( stats );
}

stat.sync( path )

Synchronously returns file system statistics for a file or directory.

var out = stat.sync( 'package.json' );
if ( out instanceof Error ) {
    throw out;
}
console.log( out );

stat.sync( path, options )

Synchronously returns file system statistics for a file or directory with options.

var out = stat.sync( 'package.json', {
    'bigint': true
});
if ( out instanceof Error ) {
    throw out;
}
console.log( out );

The returned fs.Stats instance provides these type-check methods:

  • isFile()
  • isDirectory()
  • isBlockDevice()
  • isCharacterDevice()
  • isFIFO()
  • isSocket()
  • isSymbolicLink()

The returned fs.Stats instance also provides values such as fs.Stats:

  • dev, ino, mode, nlink, uid, gid, rdev, size, blksize, blocks
  • atime, mtime, ctime, birthtime
  • atimeMs, mtimeMs, ctimeMs, birthtimeMs
  • atimeNs, mtimeNs, ctimeNs, birthtimeNs (available when bigint: true)
var out = stat.sync( 'package.json' );
if ( out instanceof Error ) {
    throw out;
}
console.log( out );

Examples

var stat = require( '@stdlib/fs/stat' );

var out = stat.sync( 'package.json' );
if ( out instanceof Error ) {
    throw out;
}
console.log( out.isFile() );

stat( 'package.json', onStat );

function onStat( error, stats ) {
    if ( error ) {
        throw error;
    }
    console.log( stats );
}

CLI

Usage

Usage: stat [options] <path>

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.

Notes

  • Relative paths are resolved relative to the current working directory.
  • Errors are written to stderr.
  • Results are written to stdout as JSON.