mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-31 07:11:33 +00:00
Code clean ups
This commit is contained in:
parent
e7fc354729
commit
5f8bad907c
@ -44,13 +44,16 @@ DiskStorage.prototype._handleFile = function _handleFile (req, file, cb) {
|
||||
if (!file._ischunk) {
|
||||
hash = blake3.createHash()
|
||||
file.stream.on('data', d => hash.update(d))
|
||||
file.stream.on('error', err => {
|
||||
const onerror = function (err) {
|
||||
hash.dispose()
|
||||
return cb(err)
|
||||
})
|
||||
cb(err)
|
||||
}
|
||||
file.stream.on('error', onerror)
|
||||
outStream.on('error', onerror)
|
||||
} else {
|
||||
outStream.on('error', cb)
|
||||
}
|
||||
|
||||
outStream.on('error', cb)
|
||||
outStream.on('finish', function () {
|
||||
cb(null, {
|
||||
destination,
|
||||
|
@ -508,30 +508,32 @@ self.actuallyFinishChunks = async (req, res, user) => {
|
||||
|
||||
self.combineChunks = async (destination, uuid) => {
|
||||
let errorObj
|
||||
const writeStream = fs.createWriteStream(destination, { flags: 'a' })
|
||||
const outStream = fs.createWriteStream(destination, { flags: 'a' })
|
||||
const hash = blake3.createHash()
|
||||
|
||||
outStream.on('error', error => {
|
||||
hash.dispose()
|
||||
errorObj = error
|
||||
})
|
||||
|
||||
try {
|
||||
chunksData[uuid].chunks.sort()
|
||||
for (const chunk of chunksData[uuid].chunks)
|
||||
await new Promise((resolve, reject) => {
|
||||
const stream = fs.createReadStream(path.join(chunksData[uuid].root, chunk))
|
||||
stream.pipe(writeStream, { end: false })
|
||||
stream.pipe(outStream, { end: false })
|
||||
|
||||
stream.on('data', d => hash.update(d))
|
||||
stream.on('error', error => {
|
||||
hash.dispose()
|
||||
reject(error)
|
||||
})
|
||||
|
||||
stream.on('error', reject)
|
||||
stream.on('end', () => resolve())
|
||||
})
|
||||
} catch (error) {
|
||||
hash.dispose()
|
||||
errorObj = error
|
||||
}
|
||||
|
||||
// Close stream
|
||||
writeStream.end()
|
||||
outStream.end()
|
||||
|
||||
// Re-throw error
|
||||
if (errorObj) throw errorObj
|
||||
|
Loading…
Reference in New Issue
Block a user