Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
/ ChecksumJS Public archive

Node checksum utility - Simple as Useful

License

Notifications You must be signed in to change notification settings

Loxoz/ChecksumJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChecksumJS

Node checksum utility - Simple as Useful

Build Status NPM version

Import:

const Checksum = require("checksumjs");
/* as standalone in your ./libs folder (download from github) */
const Checksum = require("./libs/Checksum.js");

Example & Tutorial:

/**
 * Global options = Checksum.defaultoptions:
 *   {String} algorithm (default: sha1)
 *    -> hash algorithm, values depends on your OpenSSL,
 *       use Checksum.getHashes() for the list,
 *   {String} encoding (default: hex)
 *    -> encoding of the string
 */
var defaultoptions = Checksum.defaultoptions;

/**
 * Checksum from string:
 *  Checksum(value, options) -> return String
 *   {String} value   -> String to sum from hash,
 *   {Object} options -> Global options
 */
var sum = Checksum("Hello World!", { algorithm: 'md5' });
/* -> ed076287532e86365e841e92bfc50d8c */

if (sum == 'ed076287532e86365e841e92bfc50d8c') {
    console.log("Valid string!");
}

/**
 * Checksum from file:
 *  Checksum.file(file,[ options,][ callback])
 *   {File} file           -> file to checksum
 *   {Object} [options]    -> Global options
 *   {Function} [callback] -> callback function
 * promise: Checksum.fileAsync
 */
Checksum.file("archive.zip", (err, sum) => {
    if (sum == 'blah') {
        console.log("Valid archive!");
    }
});

Checksum.file("archive.7z", { algorithm: 'md5' }, (err, sum) => {
    console.log("Archive md5: " + sum);
});

/**
 * Checksum from stream:
 *  Checksum.stream(stream,[ options,][ callback])
 *   {Stream} stream       -> stream to checksum
 *   {Object} [options]    -> Global options
 *   {Function} [callback] -> callback function
 * promise: Checksum.streamAsync
 */
Checksum.stream(mystream, (err, sum) => {
    console.log("Sum of stream: " + sum);
});

/**
 * Get available hashes:
 *  Checksum.getHashes() -> return Array of string
 */
if (Checksum.getHashes().indexOf('sha1') >= 0) {
    console.log('sha1 hash supported!');
} else {
    console.log('aww! sha1 hash not avalible here');
}

/* This is easy as that! */

wink to checksum package 😉

Hope you ❤️Enjoy my work, Leave a ⭐️Star if you found it useful to support me

About

Node checksum utility - Simple as Useful

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published