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

readavailable is not working for IOStream on a file #36004

Closed
HidemotoNakada opened this issue May 23, 2020 · 6 comments · Fixed by #36036
Closed

readavailable is not working for IOStream on a file #36004

HidemotoNakada opened this issue May 23, 2020 · 6 comments · Fixed by #36036
Assignees
Labels
docs This change adds or pertains to documentation io Involving the I/O subsystem: libuv, read, write, etc.

Comments

@HidemotoNakada
Copy link

I believe readavailable does not work properly for IOStream on a file.

julia> open("tmpfile", "w") do io 
           write(io, "Hello world!")
       end
12

julia> f = open("tmpfile", "r")
IOStream(<file tmpfile>)

julia> readavailable(f)
0-element Array{UInt8,1}

While the file obviously has 12 bytes, 'readavailable' does not return any byte.

Version info is the following.

julia> versioninfo()
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4

'readavailable' works fine for stdio.

Thank you in advance.

@JeffBezanson
Copy link
Member

readavailable can return whatever it finds convenient. In this case, it returns whatever happens to be buffered already. This is not a very good function, because there's no particular guarantee on what it will return. To read the whole file, just use read.

@HidemotoNakada
Copy link
Author

Thank you, but at least, the documents should explicitly define the specification of the function.

@StefanKarpinski
Copy link
Member

It’s true: the readavailable doc claims to block if no data is available, which is incorrect.

@StefanKarpinski StefanKarpinski added docs This change adds or pertains to documentation io Involving the I/O subsystem: libuv, read, write, etc. labels May 25, 2020
@strickek
Copy link
Contributor

Not new: #16821

@KristofferC
Copy link
Member

Yeah, closing as dup.

@JeffBezanson
Copy link
Member

Wait a minute, looking at this again, it is a bug in this particular method. All the other methods make sure to return at least one byte.

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

Successfully merging a pull request may close this issue.

5 participants