File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -12,18 +12,17 @@ This function is similar to `Base.unsafe_read` but is different in some points:
12
12
- It does not block if there are buffered data in `input`.
13
13
"""
14
14
function unsafe_read (input:: IO , output:: Ptr{UInt8} , nbytes:: Int ):: Int
15
- nread = 0
15
+ p = output
16
16
navail = nb_available (input)
17
17
if navail == 0 && nbytes > 0 && ! eof (input)
18
18
b = read (input, UInt8)
19
- unsafe_store! (output , b)
20
- output += 1
19
+ unsafe_store! (p , b)
20
+ p += 1
21
21
nbytes -= 1
22
- nread += 1
23
22
navail = nb_available (input)
24
23
end
25
24
n = min (navail, nbytes)
26
- Base. unsafe_read (input, output , n)
27
- nread += n
28
- return nread
25
+ Base. unsafe_read (input, p , n)
26
+ p += n
27
+ return Int (p - output)
29
28
end
Original file line number Diff line number Diff line change @@ -79,6 +79,13 @@ using Base.Test
79
79
@test eof (stream)
80
80
close (stream)
81
81
82
+ stream = TranscodingStream (Identity (), IOBuffer (" foo" ))
83
+ out = zeros (UInt8, 3 )
84
+ @test nb_available (stream) == 0
85
+ @test TranscodingStreams. unsafe_read (stream, pointer (out), 10 ) == 3
86
+ @test out == b " foo"
87
+ close (stream)
88
+
82
89
s = TranscodingStream (Identity (), IOBuffer (b " baz" ))
83
90
@test endof (s. state. buffer1) == 0
84
91
read (s, UInt8)
You can’t perform that action at this time.
0 commit comments