# file-stat [![NPM version](https://badge.fury.io/js/file-stat.svg)](http://badge.fury.io/js/file-stat)

> Set the `stat` property on a file object. Abstraction from vinyl-fs to support stream or non-stream usage.

This is inspired by the `file.stat` code in [vinyl-fs](http://github.com/wearefractal/vinyl-fs). I needed a function that essentially did the same thing but could be used with stream or non-stream code.

## Install

Install with [npm](https://www.npmjs.com/)

```sh
$ npm i file-stat --save
```

## Usage

```js
var through = require('through2');
var stats = require('file-stat');

function toStream(fp) {
  var stream = through.obj();
  stream.write({path: fp});
  stream.end();
  return stream;
}

toStream('README.md')
  .pipe(stats())
  .on('data', function (file) {
    // adds `stat` object to file
    console.log(file.stat);
  })
  .on('end', function () {
    console.log('Done.');
  });
```

**async**

A `.getStats()` method is exposed for non-stream usage.

```js
stats.getStats({path: 'README.md'}, function (err, res) {
  // (typeof res.stat === 'object') => true
});
```

## Related projects

* [file-contents](https://www.npmjs.com/package/file-contents): Set the `contents` property on a file object. Abstraction from vinyl-fs to support stream or… [more](https://www.npmjs.com/package/file-contents) | [homepage](https://github.com/jonschlinkert/file-contents)
* [file-symlinks](https://www.npmjs.com/package/file-symlinks): Resolve symlinks and expose the `stat` property on a file object. | [homepage](https://github.com/jonschlinkert/file-symlinks)
* [stream-loader](https://www.npmjs.com/package/stream-loader): create a read stream from a glob of files. can be used as a loader-cache… [more](https://www.npmjs.com/package/stream-loader) | [homepage](https://github.com/jonschlinkert/stream-loader)
* [vinyl](https://www.npmjs.com/package/vinyl): A virtual file format | [homepage](http://github.com/gulpjs/vinyl)
* [vinyl-fs](https://www.npmjs.com/package/vinyl-fs): Vinyl adapter for the file system | [homepage](http://github.com/wearefractal/vinyl-fs)

## Running tests

Install dev dependencies:

```sh
$ npm i -d && npm test
```

## Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/file-stat/issues/new).

## Author

**Jon Schlinkert**

+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

## License

Copyright © 2015 Jon Schlinkert
Released under the MIT license.

***

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 05, 2015._