Socket
Socket
Sign inDemoInstall

fs-compare

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-compare

Compare file stats of two files.


Version published
Maintainers
1
Created
Source

fs-compare

Build Status

Simple comparison of attributes of two files.

Installation

npm install fs-compare

Usage

Asynchronous

var fsCompare = require('fs-compare');

var modifiedTime = function (fileName, cb) {
  fs.stat(fileName, function (err, stat) {
    if (err) {
      return cb(err);
    }
    return cb(null, stat.mtime);
  });
};

fsCompare(modifiedTime, 'foo.txt', 'bar.txt', function (err, diff) {
  // diff is -1 if foo.txt was created before bar.txt
  // diff is 0 if foo.txt was created at the same time as bar.txt
  // diff is 1 if foo.txt was created after bar.txt
});

Stat helpers are included, so you can shortcut the above with:

var fsCompare = require('fs-compare');

fsCompare.ctime('foo.txt', 'bar.txt', function (err, diff) {
  // diff is -1 if foo.txt was created before bar.txt
  // diff is 0 if foo.txt was created at the same time as bar.txt
  // diff is 1 if foo.txt was created after bar.txt
});

Synchronous

var fsCompareSync = require('fs-compare').sync;

var modifiedTime = function (fileName, cb) {
  return fs.statSync(fileName).mtime;
};

var diff = fsCompareSync(modifiedTime, 'foo.txt', 'bar.txt');

// diff is -1 if foo.txt was created before bar.txt
// diff is 0 if foo.txt was created at the same time as bar.txt
// diff is 1 if foo.txt was created after bar.txt

Stat helpers are included, so you can shortcut the above with:

var fsCompareSync = require('fs-compare').sync;

var diff = fsCompareSync.mtime(modifiedTime, 'foo.txt', 'bar.txt');

// diff is -1 if foo.txt was created before bar.txt
// diff is 0 if foo.txt was created at the same time as bar.txt
// diff is 1 if foo.txt was created after bar.txt

API

fsCompare(testFunction, fileNameA, fileNameB, callback)

  • testFunction - Function with parameters (fileName, cb) which tests the file and returns the value to be compared on the callback.
  • fileNameA, fileNameB - Filenames of files to be tested.
  • callback - Callback to accept (error, diff), where diff is:
    • -1 - file A tests less than file B
    • 0 - file A tests equal to file B
    • 1 - file A tests greater than file B

fsCompare.mtime(fileNameA, fileNameB, callback)

Compares the modified timestamp of the files.

fsCompare.ctime(fileNameA, fileNameB, callback)

Compares the created timestamp of the files.

fsCompare.atime(fileNameA, fileNameB, callback)

Compares the access timestamp of the files.

fsCompare.size(fileNameA, fileNameB, callback)

Compares the size of the files.

fsCompareSync(testFunction, fileNameA, fileNameB)

Synchronous version of fsCompare.

fsCompareSync.mtime(fileNameA, fileNameB, callback)

Synchronous version of fsCompare.mtime.

fsCompareSync.ctime(fileNameA, fileNameB, callback)

Synchronous version of fsCompare.ctime.

fsCompareSync.atime(fileNameA, fileNameB, callback)

Synchronous version of fsCompare.atime.

fsCompareSync.size(fileNameA, fileNameB, callback)

Synchronous version of fsCompare.size.

Keywords

FAQs

Package last updated on 08 Jun 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc