mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Tidy up md5 hash generation
This commit is contained in:
parent
49ad408b30
commit
3b011258d2
2 changed files with 6 additions and 24 deletions
|
@ -1,7 +1,6 @@
|
|||
const fs = require('fs')
|
||||
const glob = require('glob')
|
||||
const path = require('path')
|
||||
const crypto = require('crypto')
|
||||
const rimraf = require('rimraf')
|
||||
const Stream = require('stream')
|
||||
const { promisify, callbackify } = require('util')
|
||||
|
@ -105,19 +104,6 @@ async function getFileMd5Hash(location, filename) {
|
|||
}
|
||||
}
|
||||
|
||||
async function _getFileMd5HashForPath(fullPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const readStream = fs.createReadStream(fullPath)
|
||||
const hash = crypto.createHash('md5')
|
||||
hash.setEncoding('hex')
|
||||
readStream.on('end', () => {
|
||||
hash.end()
|
||||
resolve(hash.read())
|
||||
})
|
||||
pipeline(readStream, hash).catch(reject)
|
||||
})
|
||||
}
|
||||
|
||||
async function copyFile(location, fromName, toName) {
|
||||
const filteredFromName = filterName(fromName)
|
||||
const filteredToName = filterName(toName)
|
||||
|
@ -245,3 +231,8 @@ module.exports = {
|
|||
directorySize
|
||||
}
|
||||
}
|
||||
|
||||
async function _getFileMd5HashForPath(fullPath) {
|
||||
const stream = fs.createReadStream(fullPath)
|
||||
return PersistorHelper.calculateStreamMd5(stream)
|
||||
}
|
||||
|
|
|
@ -20,16 +20,7 @@ function calculateStreamMd5(stream) {
|
|||
const hash = crypto.createHash('md5')
|
||||
hash.setEncoding('hex')
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
pipeline(stream, hash)
|
||||
.then(() => {
|
||||
hash.end()
|
||||
resolve(hash.read())
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
return pipeline(stream, hash).then(() => hash.read())
|
||||
}
|
||||
|
||||
// verifies the md5 hash of a file against the supplied md5 or the one stored in
|
||||
|
|
Loading…
Reference in a new issue