- Newest
- Most votes
- Most comments
The issue you're facing is likely due to the way you're calculating the byte ranges. In your code, the ranges are overlapping, which is causing corruption in the final merged file.
Here's a better way to calculate the ranges to avoid overlap:
int partSize = 10485760; // 10MB
long fileSize = 31981568; // Size of the original file
List<ByteRange> ranges = new List<ByteRange>();
for (long start = 0; start < fileSize; start += partSize)
{
long end = Math.Min(start + partSize - 1, fileSize - 1);
ranges.Add(new ByteRange(start, end));
}
This code will generate non-overlapping byte ranges for your file, ensuring that each part contains unique data. The ranges will look like this:
ByteRange(0, 10485759)
ByteRange(10485760, 20971519)
ByteRange(20971520, 31457279)
ByteRange(31457280, 31981567)
Note that the last range ends at 31981567 because byte ranges are inclusive on both ends.
After downloading the parts using these ranges, you should be able to merge them without any corruption or checksum mismatch.
Also, make sure that you're merging the parts in the correct order. The copy command in CMD will concatenate the files in the order they're listed
I see I have to start at zero instead of one. So for this file the bytes are 0 - 31981567 not 1 - 31981568.
I was also having and issue when merging the files using copy. I was getting a file that was 1 byte larger for some odd reason. I merged the part using code, much the same why they will be in the final app, which work perfectly.
Thanks for you help.
Relevant content
- asked a year ago
- asked a year ago
- AWS OFFICIALUpdated 3 years ago