Module: Shrine::Plugins::DataUri::FileMethods

Defined in:
lib/shrine/plugins/data_uri.rb

Instance Method Summary collapse

Instance Method Details

#base64Object

Returns contents of the file base64-encoded.



139
140
141
142
143
144
# File 'lib/shrine/plugins/data_uri.rb', line 139

def base64
  binary = open { |io| io.read }
  result = Base64.strict_encode64(binary)
  binary.clear # deallocate string
  result
end

#data_uriObject

Returns the data URI representation of the file.



134
135
136
# File 'lib/shrine/plugins/data_uri.rb', line 134

def data_uri
  @data_uri ||= "data:#{mime_type || "text/plain"};base64,#{base64}"
end