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.
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_uri ⇒ Object
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 |