You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reading more bytes than a file contains yields EOF instead of data #12892
The most recent Rust upgrade for Servo has uncovered a problem with the code at larsbergstrom/servo@3445fc9#diff-b8f19d42333587901f805bdc9be6df88R16 . A call to reader.read_bytes(1024) on a file that is <1024 bytes long does not yield any data, and instead returns an immediate EOF error result.
This appears to the documented behavior of read_bytes (not be be confused with read). It basically reads until it has read the specified number of bytes or there is an error.
I'll note that using push_bytes doesn't seem to be much of an improvement if you're trying to read a file in chunks; I'm seeing similar behaviour with it.
push_bytes will also bubble up an EOF if there are less than the amount requested, but the bytes that were read will still have been pushed to the buffer. All read_bytes does is call push_bytes on a new ~[u8].
Activity
alexcrichton commentedon Mar 14, 2014
Hm, it may be something else going on, this appears to work for me:
zkamsler commentedon Mar 14, 2014
This appears to the documented behavior of
read_bytes(not be be confused withread). It basically reads until it has read the specified number of bytes or there is an error.jdm commentedon Mar 14, 2014
Wow. That seems like a really niche use case in which it's acceptable to potentially lose bytes.
alexcrichton commentedon Mar 14, 2014
Ah sorry, yes, I see what's going on now.
read_bytesis for reading an exact number of bytes, not for generally "read some bytes".Perhaps is should be renamed to
read_exact, it may have made more sense when conditions existed.jdm commentedon Mar 14, 2014
I'll note that using push_bytes doesn't seem to be much of an improvement if you're trying to read a file in chunks; I'm seeing similar behaviour with it.
zkamsler commentedon Mar 14, 2014
push_byteswill also bubble up an EOF if there are less than the amount requested, but the bytes that were read will still have been pushed to the buffer. Allread_bytesdoes is callpush_byteson a new~[u8].See source:
https://github.com/mozilla/rust/blob/b4d324334cb48198c27d782002d75eba14a6abde/src/libstd/io/mod.rs#L380
But it definitely is not that great if you don't care about reading the exact number of bytes.
sfackler commentedon Mar 14, 2014
👍 to
read_exact.auto merge of #12907 : alexcrichton/rust/issue-12892, r=brson
Auto merge of rust-lang#12892 - meithecatte:needless-borrows-mutrefs,…
Auto merge of rust-lang#12892 - meithecatte:needless-borrows-mutrefs,…
Auto merge of rust-lang#12892 - meithecatte:needless-borrows-mutrefs,…
Auto merge of rust-lang#12892 - meithecatte:needless-borrows-mutrefs,…