Closed KennyChenBasis closed 6 months ago
thanks for reviewing, your analysis is correct. when the size is large it would result in incomplete segments. I will fix it or if you are willing feel free to create a PR.
you can use divmod to easily get the partition_size and the remaining bytes
partition_size, add_bytes = divmod(size, segments)
LGTM
Hi,
I was reviewing this project's code and came across what looks to be some distasteful code in
create_segment_table
. Inend -= 1
should also be applied to the last segment; if the size is200
, the last byte is at index199
(0-index, inclusive).There is also careless use of floating points --
int(size / segments * segments)
doesn't always equalsize
, e.g.int(109 / 11 * 11)
returns108
. This problem is accidentally mitigated by the above problem. However, cases where the calculation is2
(or greater) less can also occur, though you'll need very large files:int(9999999999999966 / 17 * 17)
returns9999999999999964
.Setting the last segment's
end
assize - 1
is acceptable, though the sane thing to do is to also havepartition_size
be an int.