-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Source::readFully inconsistent with other read methods #139
Comments
I believe you’re referring to the
I believe Streaming SourceSuppose I use
I believe 1 is bad behavior because it requires us to load almost 10 GiB of data into memory before proceeding. The readFully() function should do streaming. Not streaming the 8 bytes of readLong() one-at-a-time is different here, because the API returns all 8 bytes as a unit. I believe 2 is bad behavior because it’s non-deterministic. Any internal buffer size should not have user-observable effects. If the internal buffer size was 11 billion bytes vs. 8 KiB, the behavior here is probably quite different. Therefore I claim that 3 is the least bad of our options. Yes it sucks to waste effort copying data if the overall operation is going to ultimately fail. But that’s decidedly not on the happy-path. Buffered SourceIf the source was instead a I believe that by the Liskov Substitution Principle (LSP) it’s better for Okio to implement the same behavior regardless of the type of the source. Doing LSP ensures that if you use a buffer in tests, and a streaming source in production, your tests remain representative of production behavior. |
@swankjesse Should the source be fully consumed by |
Lemme rank some potential goals for an I/O function:
For For For |
After all, it seems fine to have slightly different consumption guarantees for different methods, it just needs to be explicitly described in the documentation. |
Most of
Source'
s read* methods don't consume any data from the source if there are not enough bytes to complete an operation. For example,Source::readLong
called on a source containing less than 8 bytes will throw theEOFException
, and bytes buffered by the source will remain untouched and available for reading.At the same time,
Source::readFully(sink: RawSink, byteCount: Long)
will consume data from the source even if the operation is terminated with an exception due to the source containing less thanbyteCount
bytes.The latter is inconsistent with other read operations and should be fixed (or there should be a reason for it to behave in such a way).
The text was updated successfully, but these errors were encountered: