import sha1 from "sha.js/sha1" ; import sha256 from "sha.js/sha256" ; import { IsoBuffer } from "./bufferNode" ; param file param algorithm param hashEncoding returns export async function hashFile ( file , algorithm = "SHA-1" , hashEncoding = "hex" ) { let engine ; switch ( algorithm ) { case "SHA-1" : { engine = new sha1 ( ) ; break ; } case "SHA-256" : { engine = new sha256 ( ) ; break ; } } return engine . update ( file ) . digest ( hashEncoding ) as string ; } param file returns export async function gitHashFile ( file ) { const size = file . byteLength ; const filePrefix = `blob ${ size . toString ( ) }${ String . fromCharCode ( 0 ) }` ; const engine = new sha1 ( ) ; return engine . update ( filePrefix ) . update ( file ) . digest ( "hex" ) as string ; }