Skip to content

Creating hash digests of files or strings. 支持对 文件或文本 的加密摘要计算。例如 md5、sha 等算法。

Notifications You must be signed in to change notification settings

relax-code-relax-life/hash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Creating hash digests of files or strings. Such as md5, sha, and so on.

Installation

npm install relax-hash

API

const {
    algorithms,
    hashFile, hashFileSync, hashFilePromise,
    hashContent, hashContentSync, hashContentPromise,
    hashStream
} = require('relax-hash');

algorithms

string[]

An array of the names of the supported hash algorithms, such as "md5","sha256".

hashFile

function (filePath: string | Buffer | URL, algorithm: string, callback: (err: Error, data: string) => void): void

const filePath = 'test.txt';
hashFile(filePath, 'md5', (err, md5) => {
    console.log(md5);
})

hashFileSync

function (filePath: string | Buffer | URL, algorithm = 'md5'): string

const md5 = hashFileSync('test.txt');
console.log(md5)

hashFilePromise

async function (filePath: string | Buffer | URL, algorithm = 'md5'): Promise<string>

hashFilePromise('test.txt').then(md5 => console.log(md5))

hashContent

function (content: string, algorithm: string, callback: (err: Error, data: string) => void): void

hashContent('testContent', 'md5', (err, md5) => {
    console.log(md5);
    //"bae941e0d1cdf42b75d6d0ef6bd7d25a"
})

hashContentSync

function (content: string, algorithm = 'md5'): string

console.log(hashContentSync('testContent')); // bae941e0d1cdf42b75d6d0ef6bd7d25a

hashContentPromise

function (content: string, algorithm = 'md5'): Promise<string>

hashContentPromise('testContent').then(md5 => console.log(md5))

hashStream

function (algorithm: string, callback: (err: Error, data: string) => void): stream.Writable

该方法返回一个可写流(准确的说,是Hash实例),计算写入流的数据的hash值。

const stream = hashStream('md5', (err, md5) => {
    console.log(md5);
    //"bae941e0d1cdf42b75d6d0ef6bd7d25a"
});
stream.end('testContent');

About

Creating hash digests of files or strings. 支持对 文件或文本 的加密摘要计算。例如 md5、sha 等算法。

Topics

Resources

Stars

Watchers

Forks