diff --git a/Project.toml b/Project.toml index c7a26f0..9a88e75 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BoundedStreams" uuid = "819c7365-da23-433e-86d1-f9a07e67aad6" authors = ["Klaus Crusius "] -version = "0.3" +version = "0.3.1" [compat] julia = "1.3" diff --git a/src/BoundedStreams.jl b/src/BoundedStreams.jl index d1d15fe..4580afe 100644 --- a/src/BoundedStreams.jl +++ b/src/BoundedStreams.jl @@ -27,10 +27,11 @@ struct BoundedInputStream{T} <: BoundedStream{T} offset::Int length::Int close::Int + isopen::Bool function BoundedInputStream(io::T, nb::Integer; offset::Integer=0, close::Integer=nb) where T - new{T}(io, initposition!(io, offset), nb, close) + new{T}(io, initposition!(io, offset), nb, close, true) end end @@ -54,10 +55,11 @@ struct BoundedOutputStream{T} <: BoundedStream{T} offset::Int length::Int close::Int + isopen::Bool function BoundedOutputStream(io::T, nb::Integer; offset::Integer=0, close::Integer=nb) where T - new{T}(io, initposition!(io, offset), nb, close) + new{T}(io, initposition!(io, offset), nb, close, true) end end @@ -99,6 +101,7 @@ function Base.close(io::BoundedStream) seek(source, q) end end + io.isopen = false nothing end @@ -117,6 +120,7 @@ function Base.seek(io::BoundedStream, nb::Integer) end Base.seekend(io::BoundedStream) = seek(io, io.length) +Base.isopen(io::BoundedStream) = io.isopen Base.isreadable(io::BoundedStream) = io isa BoundedInputStream Base.iswritable(io::BoundedStream) = io isa BoundedOutputStream Base.mark(io::BoundedStream) = mark(io.source) diff --git a/test/runtests.jl b/test/runtests.jl index c219777..3b9cd83 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,7 +22,9 @@ file = joinpath(mkpath(abspath(@__FILE__, "..", "data")), "test.dat") @test reset(is) == 5 @test position(is) == 5 @test bytesavailable(is) == 95 + @test isopen(is) == true close(is) + @test isopen(is) == false @test bytesavailable(is) == 0 @test position(io) == 100 close(io)