mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-13 22:48:31 -05:00
13310814da
* #2606 add prettier plugin sort imprts * #2606 update pnpm-lock.yaml * #2606 update eslint rules * #2606 fixes website directory formatting Co-authored-by: Ayush Sharma <ayush.sharma@trivago.com>
22 lines
683 B
TypeScript
22 lines
683 B
TypeScript
import { Hash, createHash, pseudoRandomBytes } from 'crypto';
|
|
|
|
export const defaultTarballHashAlgorithm = 'sha1';
|
|
|
|
export function createTarballHash(): Hash {
|
|
return createHash(defaultTarballHashAlgorithm);
|
|
}
|
|
|
|
/**
|
|
* Express doesn't do ETAGS with requests <= 1024b
|
|
* we use md5 here, it works well on 1k+ bytes, but sucks with fewer data
|
|
* could improve performance using crc32 after benchmarks.
|
|
* @param {Object} data
|
|
* @return {String}
|
|
*/
|
|
export function stringToMD5(data: Buffer | string): string {
|
|
return createHash('md5').update(data).digest('hex');
|
|
}
|
|
|
|
export function generateRandomHexString(length = 8): string {
|
|
return pseudoRandomBytes(length).toString('hex');
|
|
}
|