module Strict::Data::Uri
Constants
- Error
- InvalidDataUri
- InvalidEncoder
- VERSION
Public Class Methods
decode(uri)
click to toggle source
# File lib/strict/data/uri.rb, line 18 def self.decode(uri) raise InvalidDataUri, "invalid data URI: #{uri.inspect}" unless uri.match(/^data:(.*?);(.*?),(.*)$/) encoder = Regexp.last_match(2) data = Regexp.last_match(3) case encoder when "base64" then Base64.strict_decode64(data) else raise InvalidEncoder, "missing or invalid encoder: #{encoder}" end end
encode(data, type = "text/plain")
click to toggle source
# File lib/strict/data/uri.rb, line 14 def self.encode(data, type = "text/plain") "data:#{type};base64,#{Base64.strict_encode64(data).rstrip}" end