SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs')
  2. const crypto = require('crypto')
  3.  
  4. const getHashAndSize = (file, alg = 'sha1') => new Promise((resolve, reject) => {
  5.   let size = 0
  6.   const hasher = crypto.createHash(alg, { encoding: 'hex' })
  7.   const filestream = fs.createReadStream(file)
  8.  
  9.   filestream.pipe(hasher)
  10.   filestream.on('data', (d) => { size += d.length })
  11.   filestream.on('end', () => {
  12.     hasher.end()
  13.     const hash = hasher.read()
  14.    
  15.     return resolve({ hash, size })
  16.   })
  17. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top