import { createHash , Hash } from "crypto" ; import { createReadStream , ReadStream } from "fs" ; export default class FileHash { param file param algorithm static hash ( file , algorithm ) { return new Promise ( ( ff , rj ) => { const hash = createHash ( algorithm ) ; const fileStream = createReadStream ( file ) ; fileStream . on ( "data" , chunk => { hash . update ( chunk ) ; } ) ; fileStream . on ( "end" , ( ) => { ff ( hash . digest ( "hex" ) ) ; } ) ; } ) ; } }