UNPKG

@gravityforms/gulp-tasks

Version:
25 lines (21 loc) 664 B
import crypto from 'node:crypto'; import fs from 'node:fs'; /** * @description Generate a SHA-1 hash for a file. * * @since 8.4.0 * * @param {string} filePath The path to the file. * * @return {Promise<string>} A promise that resolves with the hex-encoded SHA-1 hash. */ function generateSha1( filePath ) { return new Promise( ( resolve, reject ) => { const hash = crypto.createHash( 'sha1' ); const stream = fs.createReadStream( filePath ); stream.on( 'data', ( chunk ) => hash.update( chunk ) ); stream.on( 'end', () => resolve( hash.digest( 'hex' ) ) ); stream.on( 'error', ( err ) => reject( err ) ); } ); } export default generateSha1;