diff --git a/README.md b/README.md index 44b0573..d62a008 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ | **Release** | **Documentation** | **Maintainers** | |:---------------------------------------------------------------:|:-------------------------------------------------------------------------------:|:-------------------------------------------:| -| [![][release-img]][release-url] [![][license-img]][license-url] | [![][docs-stable-img]][docs-stable-url] [![][docs-latest-img]][docs-latest-url] | ![][maintainer-a-img] | +| [![](https://img.shields.io/github/release/BioJulia/BufferedStreams.jl.svg)](https://github.com/BioJulia/BufferedStreams.jl/releases/latest) [![](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/BioJulia/BufferedStreams.jl/blob/master/LICENSE) | [![](https://img.shields.io/badge/docs-stable-blue.svg)](https://biojulia.github.io/BufferedStreams.jl/stable) [![](https://img.shields.io/badge/docs-latest-blue.svg)](https://biojulia.github.io/BufferedStreams.jl/latest) | ![](https://img.shields.io/badge/BioJulia%20Maintainer-Ward9250-orange.svg) | ## Description @@ -31,7 +31,7 @@ BufferedStreams.jl is tested against Julia `0.6` and current `0.7-dev` on Linux, | **PackageEvaluator** | **Latest Build Status** | |:---------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------:| -| [![][pkg-0.6-img]][pkg-0.6-url] [![][pkg-0.7-img]][pkg-0.7-url] | [![][travis-img]][travis-url] [![][appveyor-img]][appveyor-url] [![][codecov-img]][codecov-url] | +| [![](https://pkg.julialang.org/badges/BufferedStreams_0.6.svg)](https://pkg.julialang.org/detail/BufferedStreams) [![](https://pkg.julialang.org/badges/BufferedStreams_0.7.svg)](https://pkg.julialang.org/detail/BufferedStreams) | [![](https://img.shields.io/travis/BioJulia/BufferedStreams.jl/master.svg?label=Linux+/+macOS)](https://travis-ci.org/BioJulia/BufferedStreams.jl) [![](https://ci.appveyor.com/api/projects/status/0f7jv901adjmp8o7?svg=true)](https://ci.appveyor.com/project/Ward9250/bufferedstreams-jl/branch/master) [![](https://codecov.io/gh/BioJulia/BufferedStreams.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/BioJulia/BufferedStreams.jl) | ## Contributing and Questions @@ -45,31 +45,3 @@ If you have a question about contributing or using this package, you are encouraged to use the [Bio category of the Julia discourse site](https://discourse.julialang.org/c/domain/bio). - - -[release-img]: https://img.shields.io/github/release/BioJulia/BufferedStreams.jl.svg -[release-url]: https://github.com/BioJulia/BufferedStreams.jl/releases/latest - -[license-img]: https://img.shields.io/badge/license-MIT-green.svg -[license-url]: https://github.com/BioJulia/BufferedStreams.jl/blob/master/LICENSE - -[docs-latest-img]: https://img.shields.io/badge/docs-latest-blue.svg -[docs-latest-url]: https://biojulia.github.io/BufferedStreams.jl/latest -[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg -[docs-stable-url]: https://biojulia.github.io/BufferedStreams.jl/stable - -[maintainer-a-img]: https://img.shields.io/badge/BioJulia%20Maintainer-Ward9250-orange.svg - -[pkg-0.6-img]: https://pkg.julialang.org/badges/BufferedStreams_0.6.svg -[pkg-0.6-url]: https://pkg.julialang.org/detail/BufferedStreams -[pkg-0.7-img]: https://pkg.julialang.org/badges/BufferedStreams_0.7.svg -[pkg-0.7-url]: https://pkg.julialang.org/detail/BufferedStreams - -[travis-img]: https://img.shields.io/travis/BioJulia/BufferedStreams.jl/master.svg?label=Linux+/+macOS -[travis-url]: https://travis-ci.org/BioJulia/BufferedStreams.jl - -[appveyor-img]: https://img.shields.io/appveyor/ci/BioJulia/BufferedStreams.jl/master.svg?label=Windows -[appveyor-url]: https://ci.appveyor.com/project/Ward9250/bufferedstreams-jl/branch/master - -[codecov-img]: https://codecov.io/gh/BioJulia/BufferedStreams.jl/branch/master/graph/badge.svg -[codecov-url]: https://codecov.io/gh/BioJulia/BufferedStreams.jl diff --git a/docs/src/inputstreams.md b/docs/src/inputstreams.md index d46b298..e8f23af 100644 --- a/docs/src/inputstreams.md +++ b/docs/src/inputstreams.md @@ -6,10 +6,10 @@ end ``` # BufferedInputStream -```@example + +```julia BufferedInputStream(open(filename)) # wrap an IOStream BufferedInputStream(rand(UInt8, 100)) # wrap a byte array -nothing # hide ``` `BufferedInputStream` wraps a source. A source can be any `IO` object, but more @@ -46,7 +46,7 @@ return an array of the bytes from the anchored position to the currened position, or `upanchor!` to return the index of the anchored position in the buffer. -```@example +```julia # print all numbers literals from a stream stream = BufferedInputStream(source) while !eof(stream) @@ -58,9 +58,6 @@ while !eof(stream) elseif isanchored(stream) println(ASCIIString(takeanchored!(stream))) end - read(stream, UInt8) - - nothing # hide end ``` diff --git a/docs/src/outputstreams.md b/docs/src/outputstreams.md index 4588ce6..502d600 100644 --- a/docs/src/outputstreams.md +++ b/docs/src/outputstreams.md @@ -6,18 +6,16 @@ end ``` # BufferedOutputStream -```@example +```julia stream = BufferedOutputStream(open(filename, "w")) # wrap an IOStream -nothing # hide ``` `BufferedOutputStream` is the converse to `BufferedInputStream`, wrapping a sink type. It also works on any writable `IO` type, as well the more specific sink interface: -```@example +```julia writebytes(sink::T, buffer::Vector{UInt8}, n::Int, eof::Bool) -nothing # hide ``` This function should consume the first `n` bytes of `buffer`. The `eof` argument @@ -31,7 +29,7 @@ indicates data was processed but should not be evicted from the buffer. `BufferedOutputStream` can be used as a simpler and often faster alternative to `IOBuffer` for incrementally building strings. -```@example +```julia out = BufferedOutputStream() print(out, "Hello") print(out, " World") diff --git a/src/bufferedoutputstream.jl b/src/bufferedoutputstream.jl index 4011646..481b27a 100644 --- a/src/bufferedoutputstream.jl +++ b/src/bufferedoutputstream.jl @@ -31,7 +31,7 @@ function BufferedOutputStream(sink::T, bufsize::Integer=default_buffer_size) whe if bufsize ≤ 0 throw(ArgumentError("buffer size must be positive")) end - return BufferedOutputStream{T}(sink, Vector{UInt8}(bufsize), 1) + return BufferedOutputStream{T}(sink, Vector{UInt8}(uninitialized, bufsize), 1) end function Base.show(io::IO, stream::BufferedOutputStream{T}) where T @@ -94,7 +94,7 @@ function Base.write(stream::BufferedOutputStream, data::Vector{UInt8}) written = n while written < length(data) flushbuffer!(stream) - n_avail = endof(stream.buffer) - stream.position + 1 + n_avail = lastindex(stream.buffer) - stream.position + 1 @assert n_avail > 0 n = min(endof(data) - written, n_avail) copyto!(stream.buffer, stream.position, data, written + 1, n) diff --git a/src/emptystream.jl b/src/emptystream.jl index 90ccac5..a802328 100644 --- a/src/emptystream.jl +++ b/src/emptystream.jl @@ -53,7 +53,7 @@ end # ---------------------- function BufferedOutputStream() - return BufferedOutputStream(Vector{UInt8}(1024)) + return BufferedOutputStream(Vector{UInt8}(uninitialized, 1024)) end function BufferedOutputStream(data::Vector{UInt8})