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.



144
145
146
147
148
149
# File 'lib/shrine/plugins/data_uri.rb', line 144

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.



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

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