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

Work around Julia 1.0.x segfault and fix doc warning #249

Merged
merged 2 commits into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/FileIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ include("registry.jl")
"""
FileIO

include("precompile.jl")
_precompile_()
if VERSION >= v"1.1.0"
include("precompile.jl")
_precompile_()
end

end
20 changes: 13 additions & 7 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ struct File{F<:DataFormat} <: Formatted{F}
end
File(fmt::Type{DataFormat{sym}}, filename) where {sym} = File{fmt}(filename)

# The docs are separated from the definition because of https://github.com/JuliaLang/julia/issues/34122
filename(@nospecialize(f::File)) = f.filename
"""
`filename(file)` returns the filename associated with `File` `file`.
"""
filename(@nospecialize(f::File)) = f.filename
filename(::File)

file_extension(@nospecialize(f::File)) = splitext(filename(f))[2]
"""
`file_extension(file)` returns the file extension associated with `File` `file`.
"""
file_extension(@nospecialize(f::File)) = splitext(filename(f))[2]
file_extension(::File)

## Stream:

Expand All @@ -58,23 +61,26 @@ Stream(::Type{F}, io::IO, filename::AbstractString) where {F<:DataFormat} = Stre
Stream(::Type{F}, io::IO, filename) where {F<:DataFormat} = Stream{F, typeof(io)}(io, filename)
Stream(file::File{F}, io::IO) where {F} = Stream{F, typeof(io)}(io, filename(file))

"`stream(s)` returns the stream associated with `Stream` `s`"
stream(@nospecialize(s::Stream)) = s.io
"`stream(s)` returns the stream associated with `Stream` `s`"
stream(::Stream)

filename(@nospecialize(s::Stream)) = s.filename
"""
`filename(stream)` returns a string of the filename
associated with `Stream` `stream`, or nothing if there is no file associated.
"""
filename(@nospecialize(s::Stream)) = s.filename
filename(::Stream)

"""
`file_extension(file)` returns a nullable-string for the file extension associated with `Stream` `stream`.
"""
function file_extension(@nospecialize(f::Stream))
fname = filename(f)
(fname == nothing) && return nothing
splitext(fname)[2]
end
"""
`file_extension(file)` returns a nullable-string for the file extension associated with `Stream` `stream`.
"""
file_extension(::Stream)

# Note this closes the stream. It's useful when you've opened
# the file to check the magic bytes, but don't want to leave
Expand Down