Skip to content

Commit 500b802

Browse files
committed
Add byte I/O support for FileBuffer.
1 parent b01aa13 commit 500b802

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FilePathsBase"
22
uuid = "48062228-2e41-5def-b9a4-89aafe57970f"
33
authors = ["Rory Finnegan"]
4-
version = "0.9.1"
4+
version = "0.9.2"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/buffer.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,18 @@ function Base.read(buffer::FileBuffer, ::Type{String})
6161
read(buffer.io, String)
6262
end
6363

64+
function Base.read(buffer::FileBuffer, ::Type{UInt8})
65+
if buffer.io.size == 0
66+
write(buffer.io, read(buffer.path))
67+
seekstart(buffer)
68+
end
69+
read(buffer.io, UInt8)
70+
end
71+
6472
#=
6573
NOTE: We need to define multiple methods because of ambiguity error with base IO methods.
6674
=#
67-
function Base.write(buffer::FileBuffer, x::Vector{UInt8})
75+
function Base.write(buffer::FileBuffer, x::Union{UInt8, Vector{UInt8}})
6876
iswritable(buffer) || throw(ArgumentError("write failed, FileBuffer is not writeable"))
6977
write(buffer.io, x)
7078
end

test/buffer.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ using FilePathsBase: FileBuffer
1414
@test !eof(io)
1515
@test read(p, String) == read(io, String)
1616
@test eof(io)
17+
seekstart(io)
18+
for b in read(p)
19+
@test read(io, UInt8) == b
20+
end
21+
@test eof(io)
1722
finally
1823
close(io)
1924
end

0 commit comments

Comments
 (0)