Module: Shrine::Plugins::DataUri::FileMethods
- Defined in:
- lib/shrine/plugins/data_uri.rb
Instance Method Summary collapse
-
#base64 ⇒ Object
Returns contents of the file base64-encoded.
-
#data_uri ⇒ Object
Returns the data URI representation of the file.
Instance Method Details
#base64 ⇒ Object
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_uri ⇒ Object
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 |