Skip to content

Commit

Permalink
add keyword arguments to IOBuffer's constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 committed Feb 4, 2018
1 parent 97a1856 commit 42ab52e
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ julia> String(take!(io))
"JuliaLang is a GitHub organization"
```
"""
IOBuffer(data::AbstractVector{UInt8}, readable::Bool=true, writable::Bool=false, maxsize::Integer=typemax(Int)) =
GenericIOBuffer(data, readable, writable, true, false, maxsize)
function IOBuffer(readable::Bool, writable::Bool)
b = IOBuffer(StringVector(32), readable, writable)
b.data[:] = 0
b.size = 0
return b
function IOBuffer(
data::AbstractVector{UInt8};
read::Union{Bool,Nothing}=nothing,
write::Union{Bool,Nothing}=nothing,
append::Union{Bool,Nothing}=nothing,
maxsize::Integer=typemax(Int))
if maxsize < 0
throw(ArgumentError("negative maxsize: $(maxsize)"))
end
flags = open_flags(read=read, write=write, append=append)
return GenericIOBuffer(data, flags.read, flags.write, true, flags.append, Int(maxsize))
end

"""
Expand All @@ -85,7 +89,16 @@ julia> String(take!(io))
"JuliaLang is a GitHub organization. It has many members."
```
"""
IOBuffer() = IOBuffer(true, true)
function IOBuffer(;read::Bool=true, write::Bool=true)
b = IOBuffer(StringVector(32), read=read, write=write)
b.data[:] = 0
b.size = 0
return b
end

# TODO: deprecate these methods?
IOBuffer(data::AbstractVector{UInt8}, read::Bool, write::Bool, maxsize::Integer=typemax(Int)) = IOBuffer(data, read=read, write=write, maxsize=maxsize)
IOBuffer(read::Bool, write::Bool) = IOBuffer(read=read, write=write)

"""
IOBuffer(size::Integer)
Expand All @@ -110,7 +123,11 @@ julia> String(take!(io))
"Hello world "
```
"""
IOBuffer(maxsize::Integer) = (x=IOBuffer(StringVector(maxsize), true, true, maxsize); x.size=0; x)
function IOBuffer(maxsize::Integer)
buf = IOBuffer(StringVector(maxsize), read=true, write=true, maxsize=maxsize)
buf.size = 0
return buf
end

# PipeBuffers behave like Unix Pipes. They are typically readable and writable, they act appendable, and are not seekable.

Expand Down

0 comments on commit 42ab52e

Please sign in to comment.