class DataStory::DataURI
Public Class Methods
from_data(file_type, data)
click to toggle source
Public: Generates a data uri from a file type and data.
# File lib/datastory/data_uri.rb, line 7 def self.from_data(file_type, data) encoded_data = Base64.strict_encode64(data) "data:#{file_type};base64,%s" % encoded_data end
from_file(path)
click to toggle source
Public: Loads the file at file_path and converts it to a data uri.
# File lib/datastory/data_uri.rb, line 13 def self.from_file(path) file_type = `file --mime -b #{path}` data = nil File.open(path, "rb") do |file| data = file.read end from_data(file_type, data) end