22#
33# \Module \Base64 provides methods for:
44#
5- # - Encoding a binary string (containing non-ASCII characters)
5+ # - \ Encoding a binary string (containing non-ASCII characters)
66# as a string of printable ASCII characters.
77# - Decoding such an encoded string.
88#
2727#
2828# require 'base64'
2929#
30- # == Encoding Character Sets
30+ # == \ Encoding Character Sets
3131#
3232# A \Base64-encoded string consists only of characters from a 64-character set:
3333#
140140# Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567"
141141# Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError
142142#
143- # \Method Base64.urlsafe_decode64 allows padding in +str+ ,
143+ # \Method Base64.urlsafe_decode64 allows padding in the encoded string ,
144144# which if present, must be correct:
145145# see {Padding}[Base64.html#module-Base64-label-Padding], above:
146146#
@@ -187,7 +187,10 @@ module Base64
187187
188188 module_function
189189
190- # Returns a string containing the RFC-2045-compliant \Base64-encoding of +bin+.
190+ # :call-seq:
191+ # Base64.encode64(string) -> encoded_string
192+ #
193+ # Returns a string containing the RFC-2045-compliant \Base64-encoding of +string+.
191194 #
192195 # Per RFC 2045, the returned string may contain the URL-unsafe characters
193196 # <tt>+</tt> or <tt>/</tt>;
@@ -220,19 +223,22 @@ def encode64(bin)
220223 [ bin ] . pack ( "m" )
221224 end
222225
226+ # :call-seq:
227+ # Base64.decode(encoded_string) -> decoded_string
228+ #
223229 # Returns a string containing the decoding of an RFC-2045-compliant
224- # \Base64-encoded string +str +:
230+ # \Base64-encoded string +encoded_string +:
225231 #
226232 # s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
227233 # Base64.decode64(s) # => "This is line 1\nThis is line 2\n"
228234 #
229- # Non-\Base64 characters in +str + are ignored;
235+ # Non-\Base64 characters in +encoded_string + are ignored;
230236 # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
231237 # these include newline characters and characters <tt>-</tt> and <tt>/</tt>:
232238 #
233239 # Base64.decode64("\x00\n-_") # => ""
234240 #
235- # Padding in +str + (even if incorrect) is ignored:
241+ # Padding in +encoded_string + (even if incorrect) is ignored:
236242 #
237243 # Base64.decode64("MDEyMzQ1Njc") # => "01234567"
238244 # Base64.decode64("MDEyMzQ1Njc=") # => "01234567"
@@ -242,7 +248,10 @@ def decode64(str)
242248 str . unpack1 ( "m" )
243249 end
244250
245- # Returns a string containing the RFC-2045-compliant \Base64-encoding of +bin+.
251+ # :call-seq:
252+ # Base64.strict_encode64(string) -> encoded_string
253+ #
254+ # Returns a string containing the RFC-2045-compliant \Base64-encoding of +string+.
246255 #
247256 # Per RFC 2045, the returned string may contain the URL-unsafe characters
248257 # <tt>+</tt> or <tt>/</tt>;
@@ -274,21 +283,24 @@ def strict_encode64(bin)
274283 [ bin ] . pack ( "m0" )
275284 end
276285
286+ # :call-seq:
287+ # Base64.strict_decode64(encoded_string) -> decoded_string
288+ #
277289 # Returns a string containing the decoding of an RFC-2045-compliant
278- # \Base64-encoded string +str +:
290+ # \Base64-encoded string +encoded_string +:
279291 #
280292 # s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK"
281293 # Base64.strict_decode64(s) # => "This is line 1\nThis is line 2\n"
282294 #
283- # Non-\Base64 characters in +str+ not allowed;
295+ # Non-\Base64 characters in +encoded_string+ are not allowed;
284296 # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
285297 # these include newline characters and characters <tt>-</tt> and <tt>/</tt>:
286298 #
287299 # Base64.strict_decode64("\n") # Raises ArgumentError
288300 # Base64.strict_decode64('-') # Raises ArgumentError
289301 # Base64.strict_decode64('_') # Raises ArgumentError
290302 #
291- # Padding in +str +, if present, must be correct:
303+ # Padding in +encoded_string +, if present, must be correct:
292304 #
293305 # Base64.strict_decode64("MDEyMzQ1Njc") # Raises ArgumentError
294306 # Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567"
@@ -298,7 +310,10 @@ def strict_decode64(str)
298310 str . unpack1 ( "m0" )
299311 end
300312
301- # Returns the RFC-4648-compliant \Base64-encoding of +bin+.
313+ # :call-seq:
314+ # Base64.urlsafe_encode64(string) -> encoded_string
315+ #
316+ # Returns the RFC-4648-compliant \Base64-encoding of +string+.
302317 #
303318 # Per RFC 4648, the returned string will not contain the URL-unsafe characters
304319 # <tt>+</tt> or <tt>/</tt>,
@@ -332,16 +347,19 @@ def urlsafe_encode64(bin, padding: true)
332347 str
333348 end
334349
335- # Returns the decoding of an RFC-4648-compliant \Base64-encoded string +str+:
350+ # :call-seq:
351+ # Base64.urlsafe_decode64(encoded_string) -> decoded_string
352+ #
353+ # Returns the decoding of an RFC-4648-compliant \Base64-encoded string +encoded_string+:
336354 #
337- # +str + may not contain non-Base64 characters;
355+ # +encoded_string + may not contain non-Base64 characters;
338356 # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
339357 #
340358 # Base64.urlsafe_decode64('+') # Raises ArgumentError.
341359 # Base64.urlsafe_decode64('/') # Raises ArgumentError.
342360 # Base64.urlsafe_decode64("\n") # Raises ArgumentError.
343361 #
344- # Padding in +str +, if present, must be correct:
362+ # Padding in +encoded_string +, if present, must be correct:
345363 # see {Padding}[Base64.html#module-Base64-label-Padding], above:
346364 #
347365 # Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567"
0 commit comments