File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,21 @@ function Base.length(buf::Buffer)
32
32
return length (buf. data)
33
33
end
34
34
35
+ function Base. endof (buf:: Buffer )
36
+ return buffersize (buf)
37
+ end
38
+
39
+ function Base. getindex (buf:: Buffer , i:: Integer )
40
+ @boundscheck checkbounds (buf, i)
41
+ @inbounds return buf. data[i+ buf. bufferpos- 1 ]
42
+ end
43
+
44
+ function Base. checkbounds (buf:: Buffer , i:: Integer )
45
+ if ! (1 ≤ i ≤ endof (buf))
46
+ throw (BoundsError (buf, i))
47
+ end
48
+ end
49
+
35
50
function bufferptr (buf:: Buffer )
36
51
return pointer (buf. data, buf. bufferpos)
37
52
end
Original file line number Diff line number Diff line change @@ -57,6 +57,15 @@ using Base.Test
57
57
@test read (stream, UInt8) == data[3 ]
58
58
skip (stream, 5 )
59
59
@test read (stream, UInt8) == data[9 ]
60
+
61
+ s = TranscodingStream (Identity (), IOBuffer (b " baz" ))
62
+ @test endof (s. state. buffer1) == 0
63
+ read (s, UInt8)
64
+ @test endof (s. state. buffer1) == 2
65
+ @test s. state. buffer1[1 ] === UInt8 (' a' )
66
+ @test s. state. buffer1[2 ] === UInt8 (' z' )
67
+ @test_throws BoundsError s. state. buffer1[0 ]
68
+ @test_throws BoundsError s. state. buffer1[3 ]
60
69
end
61
70
62
71
Pkg. test (" CodecZlib" )
You can’t perform that action at this time.
0 commit comments