Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

enfscompare

1.0.0 • Public • Published

Build Status Build status Codacy Badge Donate

NPM

enfscompare

Module that add compare functionality to to node fs module

This module is intended to work as a sub-module of enfs

Description

This module will add a method that allows the comparison of files and folders.

  • This module will add following methods to node fs module:
    • files
    • filesHash
    • filesSync
    • filesHashSync
    • dir
    • dirHash
    • dirSync
    • dirHashSync

Usage

enfscompare

    var enfscompare = require("enfscompare");

Errors

All the methods follows the node culture.

  • Async: Every async method returns an Error in the first callback parameter
  • Sync: Every sync method throws an Error.

Additional Methods

files

filesSync

  • files(path1, path2, [options], callback)
  • filesSync(path1, path2, [options])

Compare files in a byte-to-byte form

[options]:

  • fs (Object): an alternative fs module to use (default will be enfspatch)
  • dereference (Boolean): if true will dereference symlinks listing the items to where it points (default: false)
  • chunkSize (Number) - the size in bytes used to read files and verify equality default to (async: ReadStream._readableState.highWaterMark, sync: 8192)
    enfscompare.files("/home/name/file.txt", "/home/name/file.txt", function(err, result){
        if(result===true){
            console.log("File is equal");
        }
    });

dir

dirSync

  • dir(path1, path2, [options], callback)
  • dirSync(path1, path2, [options])

Compare files in a byte-to-byte form

[options]:

  • fs (Object): an alternative fs module to use (default will be enfspatch)
  • dereference (Boolean): if true will dereference symlinks listing the items to where it points (default: false)
  • chunkSize (Number) - the size in bytes used to read files and verify equality default to (async: ReadStream._readableState.highWaterMark, sync: 8192)
    enfscompare.dir("/home/name", "/home/another_folder_name", function(err, result){
        if(result===true){
            console.log("Directories are equal");
        }
    });

filesHash

filesHashSync

  • filesHash(path1, path2, [options], callback)
  • filesHashSync(path1, path2, [options])

Compare files with an hash NOTE: This method can't correctly tell you that the files are equal, but can tell you if they are different

[options]:

  • fs (Object): an alternative fs module to use (default will be enfspatch)
  • dereference (Boolean): if true will dereference symlinks listing the items to where it points (default: false)
  • hash (String) - the type of hash to use in comparison, default to 'sha512'
  • encoding (String) - the type of hash encoding used to compare the files, default to 'hex'
  • chunkSize (String) - the size in bytes used to read files default 8192 (Only in sync method)
    var result = enfscompare.filesHashSync("/home/name/file.txt","/home/name/file.txt");
    if(result===true){
        console.log("File is equal");
    }

dirHash

dirHashSync

  • dirHash(path1, path2, [options], callback)
  • dirHashSync(path1, path2, [options])

Compare files with an hash NOTE: This method can't correctly tell you that the files are equal, but can tell you if they are different

[options]:

  • fs (Object): an alternative fs module to use (default will be enfspatch)
  • dereference (Boolean): if true will dereference symlinks listing the items to where it points (default: false)
  • hash (String) - the type of hash to use in comparison, default to 'sha512'
  • encoding (String) - the type of hash encoding used to compare the files, default to 'hex'
  • chunkSize (String) - the size in bytes used to read files default 8192 (Only in sync method)
    var result = enfscompare.filesHashSync("/home/name","/home/another_folder_name");
    if(result===true){
        console.log("Folders are equal");
    }

Benchmarks

Run the files in benchmarks folder to check which algorithm is fastest in your machine with different file sizes

License

Creative Commons Attribution 4.0 International License

Copyright (c) 2016 Joao Parreira joaofrparreira@gmail.com GitHub

This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit CC-BY-4.0.

Install

npm i enfscompare

DownloadsWeekly Downloads

2

Version

1.0.0

License

CC-BY-4.0

Last publish

Collaborators

  • avatar