Skip to content

Commit

Permalink
Support read from IO (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
omus authored Sep 29, 2020
1 parent 3458b92 commit 5913c82
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BitIntegers"
uuid = "c3b6d118-76ef-56ca-8cc7-ebb389d030a1"
authors = ["Rafael Fourquet <[email protected]>"]
version = "0.2.3"
version = "0.2.4"

[compat]
julia = "1"
Expand Down
4 changes: 4 additions & 0 deletions src/BitIntegers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ function read(from::GenericIOBuffer, ::Type{T}) where {T<:XBI}
return x
end

function read(io::IO, ::Type{T}) where {T<:XBI}
return read!(io, Ref{T}(0))[]::T
end

function peek(from::GenericIOBuffer, ::Type{T}) where {T<:XBI}
from.readable || Base._throw_not_readable()
avail = bytesavailable(from)
Expand Down
17 changes: 15 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ end
end

@testset "read/write" begin
for X in XInts
io = IOBuffer()
function read_write_tests(io, X)
x, y = rand(X, 2)
@test write(io, x) == sizeof(x)
@test write(io, y) == sizeof(y)
Expand All @@ -296,6 +295,20 @@ end
q = deserialize(io)
@test q === true
end

@testset "IOBuffer" begin
for X in XInts
read_write_tests(IOBuffer(), X)
end
end

@testset "IOStream" begin
for X in XInts
open(tempname(), "w+") do iostream
read_write_tests(iostream, X)
end
end
end
end

@testset "rand" begin
Expand Down

2 comments on commit 5913c82

@rfourquet
Copy link
Owner

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/22169

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.4 -m "<description of version>" 5913c822ae33a9c7d0b2563e87e1407c3a96ab63
git push origin v0.2.4

Please sign in to comment.