Class: Mindee::Input::Source::Base64InputSource

Inherits:
LocalInputSource show all
Defined in:
lib/mindee/input/sources/base64_input_source.rb

Overview

Load a document from a base64 string.

Instance Attribute Summary

Attributes inherited from LocalInputSource

#file_mimetype, #filename, #io_stream

Instance Method Summary collapse

Methods inherited from LocalInputSource

#compress!, #count_pages, #pdf?, #process_pdf, #rescue_broken_pdf, #source_text?, #write_to_file

Constructor Details

#initialize(base64_string, filename, repair_pdf: false) ⇒ Base64InputSource

Returns a new instance of Base64InputSource.

Parameters:

  • base64_string (String)
  • filename (String)
  • repair_pdf (bool) (defaults to: false)


13
14
15
16
17
# File 'lib/mindee/input/sources/base64_input_source.rb', line 13

def initialize(base64_string, filename, repair_pdf: false)
  io_stream = StringIO.new(base64_string.unpack1('m*').to_s)
  io_stream.set_encoding Encoding::BINARY
  super(io_stream, filename, repair_pdf: repair_pdf)
end

Instance Method Details

#read_contents(close: true) ⇒ Array<String, [String, aBinaryString ], [Hash, nil] >

Overload of the same function to prevent a base64 from being re-encoded.

Parameters:

  • close (bool) (defaults to: true)

Returns:

  • (Array<String, [String, aBinaryString ], [Hash, nil] >)


22
23
24
25
26
27
# File 'lib/mindee/input/sources/base64_input_source.rb', line 22

def read_contents(close: true)
  @io_stream.seek(0)
  data = @io_stream.read
  @io_stream.close if close
  ['document', [data].pack('m'), { filename: Source.convert_to_unicode_escape(@filename) }]
end