Skip to content

Commit

Permalink
Avoid redefining docs warning
Browse files Browse the repository at this point in the history
Fixes #246
  • Loading branch information
timholy committed Dec 30, 2019
1 parent 0873310 commit e4a3a27
Showing 1 changed file with 13 additions and 7 deletions.
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 e4a3a27

Please sign in to comment.