confusion with base64 class methods usage

ruby

Solution

An example of usage would be:

require "base64"
Base64.strict_encode64('Stuff to be encoded')
Base64.strict_decode64("U3R1ZmYgdG8gYmUgZW5jb2RlZA==")

Strict means that white spaces / CR/LF are rejected at decode and CR/LF are not added at encode.

Note that if the folowing is accepted:

Base64.decode64("U3R1ZmYgdG8gYmUgZW5jb2RlZA==\n")

with strict the above is not accepted because of the trailing `\n` (linefeed) and the following line will throw `ArgumentError: invalid base64` exception:

Base64.strict_decode64("U3R1ZmYgdG8gYmUgZW5jb2RlZA==\n")

So strict accepts/expects only alphanumeric characters at decode and returns only alphanumeric at encode.

Please try the following and see how one encodes wraps the lines every 60 characters with `'\n'` (linefeed) and the strict doesn't:

print Base64.encode64('I will not use spaces and new lines. I will not use spaces and new lines. I will not use spaces and new lines. I will not use spaces and new lines.I will not use spaces and new lines.')


print Base64.strict_encode64('I will not use spaces and new lines. I will not use spaces and new lines. I will not use spaces and new lines. I will not use spaces and new lines.I will not use spaces and new lines.')

Problem

Could anyone help me here to understand when we need to consider the below 4 methods: ``` strict_decode64(str) strict_encode64(bin) urlsafe_encode64(bin) urlsafe_decode64(str) ``` From the doc also I didn't get any examples. So examples with explanation might be helpful for me to understand. Thanks in advance

Original source