4 ms·
As you say, the reported size is not necessarily correct so it should only be treated as a hint. And if os.read directly translates to a read syscall then you'r
by the8472 3y ago
As you say, the reported size is not necessarily correct so it should only be treated as a hint. And if os.read directly translates to a read syscall then you're also not handling short reads.
- collinmanderson 3y agoAhh ok so to be correct you have to keep reading until you get an empty read? Maybe I don’t need to query the file size at all?
- the8472 3y agoquerying the file size can be useful to choose the allocation size for a buffer. but yes, you have to keep reading until you get a zero-length read. https://man7.org/linux/man-pages/man2/read.2.html https://man7.org/linux/man-pages/man2/read.2.html > On success, the number of bytes read is returned (zero indicates end of file), [...] It is not an error if this number is smaller than the number of bytes requested