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

Add open for composed transcodingstreams #113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions src/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,48 @@
end
end

# ComposedFunction is available in Julia 1.6
@static if VERSION ≥ v"1.6"
function Base.open(

Check warning on line 182 in src/stream.jl

View check run for this annotation

Codecov / codecov/patch

src/stream.jl#L182

Added line #L182 was not covered by tests
f::Function,
code::ComposedFunction{
<:Union{<:Type{<:TranscodingStream}, <:ComposedFunction},
<:Type{<:TranscodingStream}
},
path::AbstractString
)
io = open(code, path)
try
f(io)

Check warning on line 192 in src/stream.jl

View check run for this annotation

Codecov / codecov/patch

src/stream.jl#L190-L192

Added lines #L190 - L192 were not covered by tests
finally
close(io)

Check warning on line 194 in src/stream.jl

View check run for this annotation

Codecov / codecov/patch

src/stream.jl#L194

Added line #L194 was not covered by tests
end
end

# Allow open with chained TranscodingStreams
function Base.open(

Check warning on line 199 in src/stream.jl

View check run for this annotation

Codecov / codecov/patch

src/stream.jl#L199

Added line #L199 was not covered by tests
code::ComposedFunction{
<:Union{<:Type{<:TranscodingStream}, <:ComposedFunction},
<:Type{<:TranscodingStream}
},
path::AbstractString
)
_open(typeof(code), open(path))

Check warning on line 206 in src/stream.jl

View check run for this annotation

Codecov / codecov/patch

src/stream.jl#L206

Added line #L206 was not covered by tests
end

function _open(code::Type{T}, io::IO) where {

Check warning on line 209 in src/stream.jl

View check run for this annotation

Codecov / codecov/patch

src/stream.jl#L209

Added line #L209 was not covered by tests
S <: TranscodingStream,
U <: Union{<:Type{<:TranscodingStream}, <:ComposedFunction},
T <: ComposedFunction{U,<:Type{S}}
}
_open(U, S(io))

Check warning on line 214 in src/stream.jl

View check run for this annotation

Codecov / codecov/patch

src/stream.jl#L214

Added line #L214 was not covered by tests
end

function _open(code::Type{<:Type{T}}, io::IO) where {T <: TranscodingStream}
T(io)

Check warning on line 218 in src/stream.jl

View check run for this annotation

Codecov / codecov/patch

src/stream.jl#L217-L218

Added lines #L217 - L218 were not covered by tests
end
Comment on lines +217 to +219
Copy link
Member

@mkitti mkitti Aug 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment about what this does?

end

function Base.isopen(stream::TranscodingStream)
return stream.state.mode != :close && stream.state.mode != :panic
end
Expand Down
Loading