Skip to content

Commit 87ad2ec

Browse files
committed
Merge pull request #3886 from tanmaykm/readcsv
close file handle after mmap. fixes #3884
2 parents a4fe68d + b4dacc1 commit 87ad2ec

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

base/datafmt.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,19 @@ readdlm(input, dlm::Char, T::Type, eol::Char; opts...) = readdlm_auto(input, dlm
4343

4444
function readdlm_auto(input, dlm::Char, T::Type, eol::Char, auto::Bool; opts...)
4545
optsd = val_opts(opts)
46-
isa(input, String) && (fsz = filesize(input); input = get(optsd, :use_mmap, true) && fsz < typemax(Int) ? mmap_array(Uint8, (int(fsz),), open(input, "r")) : readall(input))
46+
isa(input, String) && (fsz = filesize(input); input = get(optsd, :use_mmap, true) && fsz < typemax(Int) ? as_mmap(input,fsz) : readall(input))
4747
sinp = isa(input, Vector{Uint8}) ? ccall(:jl_array_to_string, ByteString, (Array{Uint8,1},), input) :
4848
isa(input, IO) ? readall(input) :
4949
input
5050
readdlm_string(sinp, dlm, T, eol, auto, optsd)
5151
end
5252

53+
function as_mmap(fname::String, fsz::Int64)
54+
open(fname) do io
55+
mmap_array(Uint8, (int(fsz),), io)
56+
end
57+
end
58+
5359
function ascii_if_possible(sbuff::String)
5460
isa(sbuff, ASCIIString) && return sbuff
5561

0 commit comments

Comments
 (0)