Skip to content

Commit

Permalink
Merge e4a3a27 into 2d99436
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Dec 30, 2019
2 parents 2d99436 + e4a3a27 commit 9f5bc78
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
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

0 comments on commit 9f5bc78

Please sign in to comment.