This en- and decodes data URIs.
This was inspired by data-uri. The main difference being (a) more precise error handling and (b) using Ruby's Base64.strict_encode64 instead of Base64.encode64 which prevents the addition of newline (\n) characters every 60 characters in the encoded string.
Add this line to your application's Gemfile:
gem 'strict-data-uri'And then execute:
bundle installEncode a string into a data URI:
Strict::Data::Uri.encode "string"
# => data:text/plain;base64,c3RyaW5nDecode a data URI:
Strict::Data::Uri.decode "data:text/plain;base64,c3RyaW5n"
# => stringTo run the tests:
bundle exec rakeBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/strict-data-uri.
The gem is available as open source under the terms of the MIT License.