Sha256: dddbb1380d6bafc822b60d9160e91f0d186fee97cf24a7ebfdcbe5ac305d970f

Contents?: true

Size: 680 Bytes

Versions: 422

Compression:

Stored size: 680 Bytes

Contents

module ForestLiana
  class Base64StringIO < StringIO
    class ArgumentError < StandardError; end

    attr_accessor :file_format

    def initialize(encoded_file)
      description, encoded_bytes = encoded_file.split(",")

      raise ArgumentError unless encoded_bytes
      raise ArgumentError if encoded_bytes.eql?("(null)")

      @file_format = get_file_format description
      bytes = ::Base64.decode64 encoded_bytes

      super bytes
    end

    def original_filename
      File.basename("file.#{@file_format}")
    end

    private

    def get_file_format(description)
      regex = /([a-z0-9]+);base64\z/
      regex.match(description).try(:[], 1)
    end
  end
end

Version data entries

422 entries across 422 versions & 1 rubygems

Version Path
forest_liana-7.2.1 lib/forest_liana/base64_string_io.rb
forest_liana-7.2.0 lib/forest_liana/base64_string_io.rb
forest_liana-7.1.0 lib/forest_liana/base64_string_io.rb
forest_liana-7.0.2 lib/forest_liana/base64_string_io.rb
forest_liana-7.0.1 lib/forest_liana/base64_string_io.rb
forest_liana-7.0.0 lib/forest_liana/base64_string_io.rb
forest_liana-7.0.0.beta.6 lib/forest_liana/base64_string_io.rb
forest_liana-7.0.0.beta.5 lib/forest_liana/base64_string_io.rb
forest_liana-7.0.0.beta.4 lib/forest_liana/base64_string_io.rb
forest_liana-7.0.0.beta.3 lib/forest_liana/base64_string_io.rb
forest_liana-6.6.2 lib/forest_liana/base64_string_io.rb
forest_liana-6.6.1 lib/forest_liana/base64_string_io.rb
forest_liana-6.6.0 lib/forest_liana/base64_string_io.rb
forest_liana-6.5.1 lib/forest_liana/base64_string_io.rb
forest_liana-7.0.0.beta.2 lib/forest_liana/base64_string_io.rb
forest_liana-6.5.0 lib/forest_liana/base64_string_io.rb
forest_liana-6.4.1 lib/forest_liana/base64_string_io.rb
forest_liana-7.0.0.beta.1 lib/forest_liana/base64_string_io.rb
forest_liana-6.4.0 lib/forest_liana/base64_string_io.rb
forest_liana-6.3.8 lib/forest_liana/base64_string_io.rb