Skip to content

Commit 25d60ea

Browse files
authored
fix runtime issue of IOBuffer backend (#704)
1 parent f8fefb6 commit 25d60ea

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/io/bufferedio.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ Base.show(io::IO, ::BufferedReader) = print(io, "BufferedReader")
6363

6464
function readmore!(io::BufferedReader, n::Integer)
6565
f = io.f
66-
amount = max(bytesavailable(f), n) #TODO: check if this reads way to much
66+
sz = _getsize(f)
67+
amount = min(max(n, 2^14), sz-position(f))
6768
amount < n && throw(EOFError())
6869
buffer = io.buffer
6970
pos = bufferpos(io)

src/io/io_wrappers.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,14 @@ Base.isreadable(::RWBuffer) = true
172172
Base.iswritable(::RWBuffer) = true
173173
isseekable(::RWBuffer) = true
174174

175+
_getsize(io::RWBuffer) = io.size
176+
175177
function _getsize(io::IO)
176-
try
177-
return filesize(io)
178-
catch
179-
# fallback
180-
pos = position(io)
181-
seekend(io)
182-
sz = position(io)
183-
seek(io, pos)
184-
return sz
185-
end
178+
pos = position(io)
179+
seekend(io)
180+
sz = position(io)
181+
seek(io, pos)
182+
return sz
186183
end
187184

188185
###########################################################################################

0 commit comments

Comments
 (0)