lib/carrierwave/base64/base64_string_io.rb in carrierwave-base64-2.2.0 vs lib/carrierwave/base64/base64_string_io.rb in carrierwave-base64-2.3.0

- old
+ new

@@ -1,25 +1,26 @@ module Carrierwave module Base64 class Base64StringIO < StringIO class ArgumentError < StandardError; end - attr_accessor :file_format + attr_accessor :file_format, :file_name - def initialize(encoded_file) - description, encoded_bytes = encoded_file.split(",") + def initialize(encoded_file, file_name) + description, encoded_bytes = encoded_file.split(',') raise ArgumentError unless encoded_bytes - raise ArgumentError if encoded_bytes.eql?("(null)") + raise ArgumentError if encoded_bytes.eql?('(null)') + @file_name = file_name @file_format = get_file_format description bytes = ::Base64.decode64 encoded_bytes super bytes end def original_filename - File.basename("file.#{@file_format}") + File.basename("#{@file_name}.#{@file_format}") end private def get_file_format(description)