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
4343 end
4444end
4545
46+ Base. isreadable (pipe:: Base64DecodePipe ) = ! isempty (pipe. rest) || isreadable (pipe. io)
47+ Base. iswritable (:: Base64DecodePipe ) = false
48+
4649function Base. unsafe_read (pipe:: Base64DecodePipe , ptr:: Ptr{UInt8} , n:: UInt )
4750 p = read_until_end (pipe, ptr, n)
4851 if p < ptr + n
Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ struct Base64EncodePipe <: IO
4444 end
4545end
4646
47+ Base. isreadable (:: Base64EncodePipe ) = false
48+ Base. iswritable (pipe:: Base64EncodePipe ) = iswritable (pipe. io)
49+
4750function Base. unsafe_write (pipe:: Base64EncodePipe , ptr:: Ptr{UInt8} , n:: UInt ):: Int
4851 buffer = pipe. buffer
4952 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
3838 # Byte-by-byte encode and decode.
3939 buf = IOBuffer ()
4040 pipe = Base64EncodePipe (buf)
41+ @test ! isreadable (pipe) && iswritable (pipe)
4142 for char in inputText
4243 write (pipe, UInt8 (char))
4344 end
4445 close (pipe)
4546 pipe = Base64DecodePipe (IOBuffer (take! (buf)))
47+ @test isreadable (ipipe) && ! iswritable (ipipe)
4648 decoded = UInt8[]
4749 while ! eof (pipe)
4850 push! (decoded, read (pipe, UInt8))
4951 end
5052 @test String (decoded) == inputText
5153
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+
5266 # Encode to string and decode
5367 @test String (base64decode (base64encode (inputText))) == inputText
5468
You can’t perform that action at this time.
0 commit comments