Skip to content

Instantly share code, notes, and snippets.

@JesterXL
Created May 10, 2020 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JesterXL/237e2fdfd1a3730ffb9967e34ba7c10b to your computer and use it in GitHub Desktop.
Save JesterXL/237e2fdfd1a3730ffb9967e34ba7c10b to your computer and use it in GitHub Desktop.
const getPartsAssemblerStream = s3 => bucket => key => uploadID => {
const parts = []
return new stream.Writable({
objectMode: true,
write(part, encoding, callback) {
if(getOr(false, 'isLast', part) === false) {
parts.push(part)
callback()
return true
}
debug("Done, uploading all...")
parts.push(pick(['ETag', 'PartNumber'], part))
debug("parts: %O", parts)
s3.completeMultipartUpload({
Bucket: bucket,
Key: key,
UploadId: uploadID,
MultipartUpload: {
Parts: sortBy(['PartNumber'], parts)
}
})
.promise()
.then(
result => {
debug("final upload result: %O", result)
callback(undefined, result)
}
)
.catch(
error =>
debug("error completing: %O", error) ||
callback(error)
)
return false
},
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment