I am trying to implement chunking logic based on a various file sizes from 0MB to 15MB. I have a byte array of the file but I am trying to chunk the array into chunks that are less than 5MB.
For example if I have a file that is 10.6MB (1.06e+7 bytes) I want to divide this into separate byte arrays that add up 1.06e+7 bytes. This should be able to handle any file size <15MB.
var chunkSize: Int = 5242880
for(index <- 0 to byteArraySize by chunkSize) {
if (index == 0){
tempArray = byteArray.slice(index, chunkSize)
} else{
tempArray = byteArray.slice(index+1, (index + chunkSize))
}
// upload tempArray to DB
segmentIndex = segmentIndex + 1
}
The issue I'm having with this is that the last chunk is not a proper size. It should be what is left over in the byte array after it has been chunked into 5242880 byte arrays.