Skip to content

Commit

Permalink
Move functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben J. Ward committed Aug 17, 2018
1 parent 6a40220 commit 7d90e24
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/IO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ function Base.open(f::Function, ::Type{T}, args...; kwargs...) where T <: Abstra
end
end

"""
Abstract data reader type.
See `subtypes(AbstractReader)` for all available data readers.
"""
abstract type AbstractReader <: AbstractFormattedIO end

Base.IteratorSize(::Type{T}) where T <: AbstractReader = Base.SizeUnknown()

function Base.open(::Type{T}, filepath::AbstractString, args...; kwargs...) where T <: AbstractReader
return T(open(filepath), args...; kwargs...)
end

function Base.read(input::AbstractReader)
return read!(input, eltype(input)())
end

"""
tryread!(reader::AbstractReader, output)
Expand All @@ -52,7 +69,6 @@ Try to read the next element into `output` from `reader`.
If the result could not be read, then `nothing` will be returned instead.
"""
function tryread!(reader::AbstractReader, output)
T = eltype(reader)
try
read!(reader, output)
return output
Expand All @@ -64,10 +80,6 @@ function tryread!(reader::AbstractReader, output)
end
end

function Base.read(input::AbstractReader)
return read!(input, eltype(input)())
end

function Base.iterate(reader::AbstractReader, nextone = eltype(reader)())
if tryread!(reader, nextone) === nothing
return nothing
Expand All @@ -76,19 +88,6 @@ function Base.iterate(reader::AbstractReader, nextone = eltype(reader)())
end
end

"""
Abstract data reader type.
See `subtypes(AbstractReader)` for all available data readers.
"""
abstract type AbstractReader <: AbstractFormattedIO end

Base.IteratorSize(::Type{T}) where T <: AbstractReader = Base.SizeUnknown()

function Base.open(::Type{T}, filepath::AbstractString, args...; kwargs...) where T <: AbstractReader
return T(open(filepath), args...; kwargs...)
end


"""
Abstract data writer type.
Expand Down

0 comments on commit 7d90e24

Please sign in to comment.