UNPKG

@gravityforms/gulp-tasks

Version:
20 lines (17 loc) 635 B
const crypto = require( 'crypto' ); const fs = require( 'fs' ); /** * Generates a SHA-1 hash for a file. * @param {string} filePath - The path to the file. * @returns {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 ) ); } ); } module.exports = generateSha1;