mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-02-12 08:19:07 +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) {
|
if (!file._ischunk) {
|
||||||
hash = blake3.createHash()
|
hash = blake3.createHash()
|
||||||
file.stream.on('data', d => hash.update(d))
|
file.stream.on('data', d => hash.update(d))
|
||||||
file.stream.on('error', err => {
|
const onerror = function (err) {
|
||||||
hash.dispose()
|
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 () {
|
outStream.on('finish', function () {
|
||||||
cb(null, {
|
cb(null, {
|
||||||
destination,
|
destination,
|
||||||
|
@ -508,30 +508,32 @@ self.actuallyFinishChunks = async (req, res, user) => {
|
|||||||
|
|
||||||
self.combineChunks = async (destination, uuid) => {
|
self.combineChunks = async (destination, uuid) => {
|
||||||
let errorObj
|
let errorObj
|
||||||
const writeStream = fs.createWriteStream(destination, { flags: 'a' })
|
const outStream = fs.createWriteStream(destination, { flags: 'a' })
|
||||||
const hash = blake3.createHash()
|
const hash = blake3.createHash()
|
||||||
|
|
||||||
|
outStream.on('error', error => {
|
||||||
|
hash.dispose()
|
||||||
|
errorObj = error
|
||||||
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
chunksData[uuid].chunks.sort()
|
chunksData[uuid].chunks.sort()
|
||||||
for (const chunk of chunksData[uuid].chunks)
|
for (const chunk of chunksData[uuid].chunks)
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const stream = fs.createReadStream(path.join(chunksData[uuid].root, chunk))
|
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('data', d => hash.update(d))
|
||||||
stream.on('error', error => {
|
stream.on('error', reject)
|
||||||
hash.dispose()
|
|
||||||
reject(error)
|
|
||||||
})
|
|
||||||
|
|
||||||
stream.on('end', () => resolve())
|
stream.on('end', () => resolve())
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
hash.dispose()
|
||||||
errorObj = error
|
errorObj = error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close stream
|
// Close stream
|
||||||
writeStream.end()
|
outStream.end()
|
||||||
|
|
||||||
// Re-throw error
|
// Re-throw error
|
||||||
if (errorObj) throw errorObj
|
if (errorObj) throw errorObj
|
||||||
|
Loading…
Reference in New Issue
Block a user