File tree 3 files changed +12
-19
lines changed
3 files changed +12
-19
lines changed Original file line number Diff line number Diff line change @@ -163,10 +163,6 @@ base64encode(x...) = base64encode(write, x...)
163
163
164
164
# ############################################################################
165
165
166
- # read(b::Base64Pipe, ::Type{UInt8}) = # TODO : decode base64
167
-
168
- # ############################################################################
169
-
170
166
type Base64DecodePipe <: IO
171
167
io:: IO
172
168
# reading works in blocks of 4 characters that are decoded into 3 bytes and 2 of them cached
182
178
183
179
function read (b:: Base64DecodePipe , t:: Type{UInt8} )
184
180
if length (b. cache) > 0
185
- val = shift! (b. cache)
181
+ return shift! (b. cache)
186
182
else
187
183
empty! (b. encvec)
188
184
while ! eof (b. io) && length (b. encvec) < 4
@@ -191,24 +187,21 @@ function read(b::Base64DecodePipe, t::Type{UInt8})
191
187
push! (b. encvec, c)
192
188
end
193
189
end
194
- val = b64decode! (b. encvec,b. cache)
190
+ return b64decode! (b. encvec,b. cache)
195
191
end
196
- val
197
- end
198
-
199
- function eof (b:: Base64DecodePipe )
200
- return length (b. cache) == 0 && eof (b. io)
201
192
end
202
193
203
- function close (b:: Base64DecodePipe )
204
- end
194
+ eof (b:: Base64DecodePipe ) = length (b . cache) == 0 && eof (b . io )
195
+ close (b :: Base64DecodePipe ) = nothing
205
196
206
197
# Decodes a base64-encoded string
207
198
function base64decode (s)
208
199
b = IOBuffer (s)
209
- decoded = readall (Base64DecodePipe (b))
210
- close (b)
211
- decoded
200
+ try
201
+ return readbytes (Base64DecodePipe (b))
202
+ finally
203
+ close (b)
204
+ end
212
205
end
213
206
214
207
end # module
Original file line number Diff line number Diff line change @@ -436,8 +436,8 @@ Text I/O
436
436
437
437
.. function :: base64decode(string)
438
438
439
- Decodes the base64-encoded ``string `` and returns the obtained bytes.
440
-
439
+ Decodes the base64-encoded ``string `` and returns a `` Vector{UInt8} ``
440
+ of the decoded bytes.
441
441
442
442
Multimedia I/O
443
443
--------------
Original file line number Diff line number Diff line change 24
24
rm (fname)
25
25
26
26
# Encode to string and decode
27
- @test base64decode (base64encode (inputText)) == inputText
27
+ @test utf8 ( base64decode (base64encode (inputText) )) == inputText
28
28
29
29
# Decode with max line chars = 76 and padding
30
30
ipipe = Base64DecodePipe (IOBuffer (encodedMaxLine76))
You can’t perform that action at this time.
0 commit comments