Skip to content
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

readbytes!: support the all keyword for all methods #40793

Open
StefanKarpinski opened this issue May 11, 2021 · 3 comments
Open

readbytes!: support the all keyword for all methods #40793

StefanKarpinski opened this issue May 11, 2021 · 3 comments
Assignees
Labels
io Involving the I/O subsystem: libuv, read, write, etc.

Comments

@StefanKarpinski
Copy link
Member

It is quite surprising that the readbytes! function doesn't block to fill up its buffer argument by default. Fortunately, there's a all=true keyword argument that you can pass to it to make it do so. Unfortunately, that keyword argument isn't supported by all I/O types so you still end up having to implement this logic yourself if you want to use readbytes! generically. The all keyword argument should be extended to cover all methods.

@StefanKarpinski StefanKarpinski added the io Involving the I/O subsystem: libuv, read, write, etc. label May 11, 2021
@vtjnash
Copy link
Member

vtjnash commented May 11, 2021

all=true is the default (consuming the whole stream), but you can pass all=false to only block once

@StefanKarpinski
Copy link
Member Author

I've encountered cases where it doesn't seems block. Will try to come up with an example.

@notinaboat
Copy link
Contributor

The generic readbytes! spec is "at most nb bytes" without an all= option.

julia/base/io.jl

Lines 955 to 962 in c298e4e

"""
readbytes!(stream::IO, b::AbstractVector{UInt8}, nb=length(b))
Read at most `nb` bytes from `stream` into `b`, returning the number of bytes read.
The size of `b` will be increased if needed (i.e. if `nb` is greater than `length(b)`
and enough bytes could be read), but it will never be decreased.
"""
function readbytes!(s::IO, b::AbstractArray{UInt8}, nb=length(b))

Essentially the same issue as #17070 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

No branches or pull requests

3 participants