enfscompare-promise

Add folder and file comparison method's to node fs module with promises


Keywords
byte, byte-to-byte, compare, directory, different, file, folder, equal, hash, hex, sha512
License
CC-BY-4.0
Install
npm install enfscompare-promise@1.0.0

Documentation

Build Status AppVeyor status Codacy Badge Donate

NPM

enfscompare-promise

Module that add compare functionality to to node fs module with promises

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
    • filesP
    • filesHashP
    • dirP
    • dirHashP

Usage

enfscompare-promise

    const enfscompare = require("enfscompare-promise");

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)
    const 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)
    const result = enfscompare.filesHashSync("/home/name","/home/another_folder_name");
    if(result===true){
        console.log("Folders are equal");
    }

filesP

  • filesP(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.filesP("/home/name/file.txt", "/home/name/file.txt").then(function(result){
        if(result===true){
            console.log("File is equal");
        }
    });

dirP

  • dirP(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.dirP("/home/name", "/home/another_folder_name").then(function(result){
        if(result===true){
            console.log("Directories are equal");
        }
    });

filesHashP

  • filesHash(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)
    enfscompare.filesHashP("/home/name/file.txt","/home/name/file.txt").then(function(result){
        if(result===true){
            console.log("File is equal");
        }
    });

dirHashP

  • dirHash(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)
    enfscompare.dirHashP("/home/name","/home/another_folder_name").then(function(result){
        if(result===true){
            console.log("Folders are equal");
        }
    });

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.