File tree Expand file tree Collapse file tree 1 file changed +21
-8
lines changed Expand file tree Collapse file tree 1 file changed +21
-8
lines changed Original file line number Diff line number Diff line change 1
- function unsafe_read (stream:: IO , ptr:: Ptr{UInt8} , nbytes:: Int ):: Int
1
+ # IO Functions
2
+ # ------------
3
+
4
+ """
5
+ unsafe_read(input::IO, output::Ptr{UInt8}, nbytes::Int)::Int
6
+
7
+ Copy at most `nbytes` from `input` into `output`.
8
+
9
+ This function is similar to `Base.unsafe_read` but is different in some points:
10
+ - It does not throw `EOFError` when it fails to read `nbytes` from `input`.
11
+ - It returns the number of bytes written to `output`.
12
+ - It does not block if there are buffered data in `input`.
13
+ """
14
+ function unsafe_read (input:: IO , output:: Ptr{UInt8} , nbytes:: Int ):: Int
2
15
nread = 0
3
- navail = nb_available (stream )
4
- if navail == 0 && nbytes > 0 && ! eof (stream )
5
- b = read (stream , UInt8)
6
- unsafe_store! (ptr , b)
7
- ptr += 1
16
+ navail = nb_available (input )
17
+ if navail == 0 && nbytes > 0 && ! eof (input )
18
+ b = read (input , UInt8)
19
+ unsafe_store! (output , b)
20
+ output += 1
8
21
nbytes -= 1
9
22
nread += 1
10
- navail = nb_available (stream )
23
+ navail = nb_available (input )
11
24
end
12
25
n = min (navail, nbytes)
13
- Base. unsafe_read (stream, ptr , n)
26
+ Base. unsafe_read (input, output , n)
14
27
nread += n
15
28
return nread
16
29
end
You can’t perform that action at this time.
0 commit comments