File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ struct Base64DecodePipe <: IO
43
43
end
44
44
end
45
45
46
+ Base. isreadable (pipe:: Base64DecodePipe ) = ! isempty (pipe. rest) || isreadable (pipe. io)
47
+ Base. iswritable (:: Base64DecodePipe ) = false
48
+
46
49
function Base. unsafe_read (pipe:: Base64DecodePipe , ptr:: Ptr{UInt8} , n:: UInt )
47
50
p = read_until_end (pipe, ptr, n)
48
51
if p < ptr + n
Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ struct Base64EncodePipe <: IO
44
44
end
45
45
end
46
46
47
+ Base. isreadable (:: Base64EncodePipe ) = false
48
+ Base. iswritable (pipe:: Base64EncodePipe ) = iswritable (pipe. io)
49
+
47
50
function Base. unsafe_write (pipe:: Base64EncodePipe , ptr:: Ptr{UInt8} , n:: UInt ):: Int
48
51
buffer = pipe. buffer
49
52
m = buffer. size
Original file line number Diff line number Diff line change @@ -38,17 +38,31 @@ const longDecodedText = "name = \"Genie\"\nuuid = \"c43c736e-a2d1-11e8-161f-af95
38
38
# Byte-by-byte encode and decode.
39
39
buf = IOBuffer ()
40
40
pipe = Base64EncodePipe (buf)
41
+ @test ! isreadable (pipe) && iswritable (pipe)
41
42
for char in inputText
42
43
write (pipe, UInt8 (char))
43
44
end
44
45
close (pipe)
45
46
pipe = Base64DecodePipe (IOBuffer (take! (buf)))
47
+ @test isreadable (ipipe) && ! iswritable (ipipe)
46
48
decoded = UInt8[]
47
49
while ! eof (pipe)
48
50
push! (decoded, read (pipe, UInt8))
49
51
end
50
52
@test String (decoded) == inputText
51
53
54
+ buf = IOBuffer (write= false )
55
+ pipe = Base64EncodePipe (buf)
56
+ @test ! isreadable (pipe) && ! iswritable (pipe)
57
+ @test_throws ArgumentError write (pipe, " Hello!" )
58
+ close (pipe)
59
+ buf = IOBuffer (read= false )
60
+ write (buf, " SGVsbG8h" )
61
+ pipe = Base64DecodePipe (buf)
62
+ @test ! isreadable (pipe) && ! iswritable (pipe)
63
+ @test isempty (read (pipe))
64
+
65
+
52
66
# Encode to string and decode
53
67
@test String (base64decode (base64encode (inputText))) == inputText
54
68
You can’t perform that action at this time.
0 commit comments