Skip to content

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

License

Notifications You must be signed in to change notification settings

chorks/file-stat

 
 

Repository files navigation

file-stat NPM version

Set the contents 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. I needed a function that essentially did the same thing but could be used with stream or non-stream code.

Install

Install with npm

$ npm i file-stat --save

Usage

var through = require('through2');
var stats = require('./index');

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

An .async() method is exposed for non-stream, async usage.

var stats = require('file-stat');
stats.async({path: 'README.md'}, function (err, file) {
  // results in something like:
  // {
  //   path: 'README.md',
  //   stat: { dev: 16777218,
  //     mode: 33188,
  //     nlink: 1,
  //     uid: 501,
  //     gid: 20,
  //     rdev: 0,
  //     blksize: 4096,
  //     ino: 26436116,
  //     size: 2443,
  //     blocks: 8,
  //     atime: Fri Jul 17 2015 03:01:54 GMT-0400 (EDT),
  //     mtime: Wed Jul 15 2015 02:46:55 GMT-0400 (EDT),
  //     ctime: Wed Jul 15 2015 02:46:55 GMT-0400 (EDT),
  //     birthtime: Tue Jul 14 2015 23:03:58 GMT-0400 (EDT)
  // } }
});

sync

A .sync() method is exposed for non-stream, sync usage.

var stats = require('file-stat');
var file = stats.sync({path: 'README.md'});
  // results in something like:
  // {
  //   path: 'README.md',
  //   stat: { dev: 16777218,
  //     mode: 33188,
  //     nlink: 1,
  //     uid: 501,
  //     gid: 20,
  //     rdev: 0,
  //     blksize: 4096,
  //     ino: 26436116,
  //     size: 2443,
  //     blocks: 8,
  //     atime: Fri Jul 17 2015 03:01:54 GMT-0400 (EDT),
  //     mtime: Wed Jul 15 2015 02:46:55 GMT-0400 (EDT),
  //     ctime: Wed Jul 15 2015 02:46:55 GMT-0400 (EDT),
  //     birthtime: Tue Jul 14 2015 23:03:58 GMT-0400 (EDT)
  // } }

Related projects

  • file-stat: Set the stat property on a file object in a stream. Abstraction from vinyl-fs to… more
  • file-symlinks: Resolve symlinks and expose the stat property on a file object.
  • stream-loader: create a read stream from a glob of files. can be used as a loader-cache… more
  • vinyl: A virtual file format
  • vinyl-fs: Vinyl adapter for the file system

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on July 18, 2015.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%