Skip to content

Commit 358c95e

Browse files
committed
Deprecate readmeta(::AbstractString) for readmeta(::Function, ::AbstractString)
1 parent c69f493 commit 358c95e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/Abstract/ObjectHandle.jl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,26 @@ function readmeta(io::IO)
138138
error(replace(msg, "\n" => " "))
139139
end
140140

141-
"""
142-
readmeta(path::AbstractStriong)
143-
144-
Read an Object File out from a file `path`, guessing at the type of object
145-
within the stream by calling `readmeta(io, T)` for each `T` within `ObjTypes`,
146-
and returning the first that does not throw a `MagicMismatch`.
147-
"""
148141
function readmeta(file::AbstractString)
142+
depwarn("`readmeta(file::AbstractString)` is deprecated, use the do-block variant instead.")
149143
return readmeta(open(file, "r"))
150144
end
151145

146+
"""
147+
readmeta(f::Function, file::AbstractString)
148+
149+
Do-block variant of `readmeta()`. Use via something like:
150+
151+
readmeta("libfoo.so") do f
152+
...
153+
end
154+
"""
155+
function readmeta(f::Function, file::AbstractString)
156+
io = open(file, "r")
157+
ret = f(readmeta(io))
158+
close(io)
159+
return ret
160+
end
152161

153162

154163
## IOStream-like operations

0 commit comments

Comments
 (0)