Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/node_modules/@stdlib/fs/README.md
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not edit this file.

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var f = fs;
- <span class="signature">[`resolveParentPathBy( path[, options], predicate, clbk )`][@stdlib/fs/resolve-parent-path-by]</span><span class="delimiter">: </span><span class="description">resolve a path according to a predicate function by walking parent directories.</span>
- <span class="signature">[`resolveParentPath( path[, options], clbk )`][@stdlib/fs/resolve-parent-path]</span><span class="delimiter">: </span><span class="description">resolve a path by walking parent directories.</span>
- <span class="signature">[`resolveParentPaths( paths[, options], clbk )`][@stdlib/fs/resolve-parent-paths]</span><span class="delimiter">: </span><span class="description">resolve paths from a set of paths by walking parent directories.</span>
- <span class="signature">[`stat( path[, options], clbk )`][@stdlib/fs/stat]</span><span class="delimiter">: </span><span class="description">show full details on the statistics of a file or directory.</span>
- <span class="signature">[`unlink( path, clbk )`][@stdlib/fs/unlink]</span><span class="delimiter">: </span><span class="description">remove a directory entry.</span>
- <span class="signature">[`writeFile( file, data[, options], clbk )`][@stdlib/fs/write-file]</span><span class="delimiter">: </span><span class="description">write data to a file.</span>

Expand Down Expand Up @@ -129,6 +130,8 @@ console.log( objectKeys( fs ) );

[@stdlib/fs/resolve-parent-paths]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/fs/resolve-parent-paths

[@stdlib/fs/stat]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/fs/stat

[@stdlib/fs/unlink]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/fs/unlink

[@stdlib/fs/write-file]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/fs/write-file
Expand Down
39 changes: 39 additions & 0 deletions lib/node_modules/@stdlib/fs/docs/types/index.d.ts
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not modify this file.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import rename = require( '@stdlib/fs/rename' );
import resolveParentPath = require( '@stdlib/fs/resolve-parent-path' );
import resolveParentPathBy = require( '@stdlib/fs/resolve-parent-path-by' );
import resolveParentPaths = require( '@stdlib/fs/resolve-parent-paths' );
import stat = require( '@stdlib/fs/stat' );
import unlink = require( '@stdlib/fs/unlink' );
import writeFile = require( '@stdlib/fs/write-file' );

Expand Down Expand Up @@ -449,6 +450,44 @@ interface Namespace {
*/
resolveParentPaths: typeof resolveParentPaths;

/**
* Asynchronously returns file system statistics for a file or directory.
*
* @param path - file path
* @param clbk - callback to invoke after retrieving file statistics
*
* @example
* var stat = require( '@stdlib/fs/stat' );
*
* stat( __filename, onStat );
* stat( __dirname, onStat );
*
* function onStat( error, stats ) {
* if ( error ) {
* throw error;
* }
* console.log( stats.isFile() );
* console.log( stats.isDirectory() );
* console.log( stats );
* }
*
* @example
* var out = stat.sync( __filename );
* if ( out instanceof Error ) {
* throw out;
* }
* console.log( out.isFile() );
* console.log( out );
*
* out = stat.sync( __dirname );
* if ( out instanceof Error ) {
* throw out;
* }
* console.log( out.isDirectory() );
* console.log( out );
*/
stat: typeof stat;

/**
* Asynchronously removes a directory entry.
*
Expand Down
9 changes: 9 additions & 0 deletions lib/node_modules/@stdlib/fs/lib/index.js
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not modify this file.

Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ setReadOnly( fs, 'resolveParentPathBy', require( '@stdlib/fs/resolve-parent-path
*/
setReadOnly( fs, 'resolveParentPaths', require( '@stdlib/fs/resolve-parent-paths' ) );

/**
* @name stat
* @memberof fs
* @readonly
* @type {Function}
* @see {@link module:@stdlib/fs/stat}
*/
setReadOnly( fs, 'stat', require( '@stdlib/fs/stat' ) );

/**
* @name unlink
* @memberof fs
Expand Down
256 changes: 256 additions & 0 deletions lib/node_modules/@stdlib/fs/stat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
<!--

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Stat

> Get full details on a file or directory.

<section class="usage">

## Usage

```javascript
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.

```javascript
stat( __filename, onStat );

function onStat( error, stats ) {
if ( error ) {
throw error;
}
console.log( stats.isFile() );
console.log( stats.isDirectory() );
console.log( stats.isSymbolicLink() );
console.log( stats.size );
console.log( stats.mode );
console.log( stats.atime );
}
```

#### stat( path, options, clbk )

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

```javascript
stat( __filename, {
'bigint': true
}, onStat );

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

Options:

- **bigint**: `boolean` flag indicating whether numeric values should be returned as `bigint`. Default: `false`.

```javascript
stat( __filename, onStat );

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

#### stat.sync( path )

Synchronously returns file system statistics for a file or directory.

```javascript
var out = stat.sync( __filename );
if ( out instanceof Error ) {
throw out;
}
console.log( out.isFile() );
console.log( out.isSocket() );
console.log( out.size );
console.log( out.mtimeMs );
```

#### stat.sync( path, options )

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

```javascript
var out = stat.sync( __filename, {
'bigint': true
});
if ( out instanceof Error ) {
throw out;
}
console.log( out.size );
console.log( out.birthtimeNs );
```

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:

- `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`)

```javascript
var out = stat.sync( __filename );
if ( out instanceof Error ) {
throw out;
}
console.log( out.isFile() );
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

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

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

stat( __filename, onStat );

function onStat( error, stats ) {
if ( error ) {
throw error;
}
console.log( stats.isFile() );
console.log( stats.isDirectory() );
console.log( stats.isBlockDevice() );
console.log( stats.isCharacterDevice() );
console.log( stats.isFIFO() );
console.log( stats.isSocket() );
console.log( stats.isSymbolicLink() );
console.log( stats.size );
console.log( stats.mode );
console.log( stats.uid );
console.log( stats.gid );
console.log( stats.atimeMs );
console.log( stats.mtimeMs );
console.log( stats.ctimeMs );
console.log( stats.birthtimeMs );
}
```

</section>

<!-- /.examples -->

* * *

<section class="cli">

## CLI

<section class="usage">

### Usage

```text
Usage: stat [options] <path>

Options:

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

</section>

<!-- /.usage -->

<section class="notes">

### Notes

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

</section>

<!-- /.notes -->

</section>

<!-- /.cli -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

* * *

## See Also

- <span class="package-name">[`@stdlib/fs/read-file`][@stdlib/fs/read-file]</span><span class="delimiter">: </span><span class="description">read the entire contents of a file.</span>
- <span class="package-name">[`node-fs-stats`][node-fs-stats]</span><span class="delimiter">: </span><span class="description">Official Node.js fs.Stats class.</span>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* * *
## See Also
- <span class="package-name">[`@stdlib/fs/read-file`][@stdlib/fs/read-file]</span><span class="delimiter">: </span><span class="description">read the entire contents of a file.</span>
- <span class="package-name">[`node-fs-stats`][node-fs-stats]</span><span class="delimiter">: </span><span class="description">Official Node.js fs.Stats class.</span>

You should not include content in this section.


</section>

<!-- /.related -->

<section class="links">

[node-fs-stats]: https://nodejs.org/api/fs.html#class-fsstats

<!-- <related-links> -->

[@stdlib/fs/read-file]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/fs/read-file

<!-- </related-links> -->

</section>

<!-- /.links -->
44 changes: 44 additions & 0 deletions lib/node_modules/@stdlib/fs/stat/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var bench = require( '@stdlib/bench' );
var stat = require( './../lib' ).sync;

bench( 'stat.sync', function benchmark( b ) {
var out;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = stat( __filename );
if ( out instanceof Error ) {
b.fail( out.message );
}
if ( typeof out.isFile !== 'function' ) {
b.fail( 'unexpected return value' );
}
}
b.toc();
if ( out instanceof Error ) {
b.fail( out.message );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading