Sha256: 138b64154538a6c14281b51ce1a3272d701d2575f511670b6626c38e533a70eb

Contents?: true

Size: 518 Bytes

Versions: 13

Compression:

Stored size: 518 Bytes

Contents

require 'marcel'
require 'base64'

module Chronicle
  module ETL
    module Utils
      # Utility methods for dealing with binary files
      module BinaryAttachments
        def self.filename_to_base64(filename:, mimetype: nil)
          mimetype = mimetype || guess_mimetype(filename: filename)

          "data:#{mimetype};base64,#{Base64.strict_encode64(File.read(filename))}"
        end

        def self.guess_mimetype(filename:)
          Marcel::MimeType.for(filename)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
chronicle-etl-0.5.5 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.5.4 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.5.3 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.5.2 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.5.1 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.5.0 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.4.4 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.4.3 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.4.2 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.4.1 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.4.0 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.3.1 lib/chronicle/etl/utils/binary_attachments.rb
chronicle-etl-0.3.0 lib/chronicle/etl/utils/binary_attachments.rb