Skip to content

Commit

Permalink
Merge pull request #27 from musm/master
Browse files Browse the repository at this point in the history
Update deprecated method takebuf_string and takebuf_array
  • Loading branch information
Ben J. Ward authored Jan 10, 2017
2 parents fc763c4 + 74c0c60 commit a89539e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ indicates data was processed but should not be evicted from the buffer.
out = BufferedOutputStream()
print(out, "Hello")
print(out, " World")
str = takebuf_string(out)
str = String(take!(out))
```
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.4
Compat 0.8.4
Compat 0.9.5
2 changes: 0 additions & 2 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Base.depwarn

typealias EmptyStreamSource EmptyStream

Base.@deprecate EmptyStreamSource EmptyStream
Expand Down
17 changes: 14 additions & 3 deletions src/emptystream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ end
stream.position += n
end

function Base.takebuf_array(stream::BufferedOutputStream{EmptyStream})
function Base.take!(stream::BufferedOutputStream{EmptyStream})
# TODO: benchmark resizing stream.buffer, returning it, and replacing it
# with an zero-length array, which might be fast in the common case of
# building just one array/string.
Expand All @@ -106,11 +106,22 @@ function Base.takebuf_array(stream::BufferedOutputStream{EmptyStream})
return chunk
end

if VERSION > v"0.5-"
if VERSION < v"0.6-"
function Base.takebuf_array(stream::BufferedOutputStream{EmptyStream})
# TODO: benchmark resizing stream.buffer, returning it, and replacing it
# with an zero-length array, which might be fast in the common case of
# building just one array/string.
chunk = stream.buffer[1:stream.position-1]
stream.position = 1
return chunk
end
end

if v"0.5-" < VERSION < v"0.6-"
function Base.takebuf_string(stream::BufferedOutputStream{EmptyStream})
return String(takebuf_array(stream))
end
else
elseif VERSION < v"0.5-"
function Base.takebuf_string(stream::BufferedOutputStream{EmptyStream})
chunk = takebuf_array(stream)
return isvalid(ASCIIString, chunk) ? ASCIIString(chunk) : UTF8String(chunk)
Expand Down
2 changes: 1 addition & 1 deletion test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BaseTestNext
Compat
Compat 0.9.5
14 changes: 8 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using BufferedStreams
using Compat

import Compat.String

if VERSION >= v"0.5-"
using Base.Test
else
Expand Down Expand Up @@ -307,8 +309,8 @@ end
end
flush(stream1)
flush(stream2)
@test takebuf_array(stream1) == data
@test takebuf_array(sink) == data
@test take!(stream1) == data
@test take!(sink) == data
close(stream1)
close(stream2)
@test !isopen(sink)
Expand All @@ -327,8 +329,8 @@ end
end
flush(stream1)
flush(stream2)
@test takebuf_array(stream1) == expected
@test takebuf_array(sink) == expected
@test take!(stream1) == expected
@test take!(sink) == expected
close(stream1)
close(stream2)
end
Expand All @@ -341,7 +343,7 @@ end
write(stream, c)
write(iobuf, c)
end
@test takebuf_string(stream) == takebuf_string(iobuf)
@test String(take!((stream))) == String(take!((iobuf)))
end

@testset "write_result" begin
Expand Down Expand Up @@ -372,7 +374,7 @@ end
write(stream, 0x01)
write(stream, 0x02)
flush(stream)
@test takebuf_array(stream) == [0x00, 0x01, 0x02]
@test take!(stream) == [0x00, 0x01, 0x02]
@test isopen(stream)
close(stream)
@test !isopen(stream)
Expand Down

0 comments on commit a89539e

Please sign in to comment.