Created
May 10, 2020 20:10
-
-
Save JesterXL/237e2fdfd1a3730ffb9967e34ba7c10b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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