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

Inherits:
LocalInputSource show all
Defined in:
lib/mindee/input/sources.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_pdf_pages, #pdf?, #process_pdf, #rescue_broken_pdf, #source_text?

Constructor Details

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

Returns a new instance of Base64InputSource.

Parameters:

  • base64_string (String)
  • filename (String)
  • fix_pdf (Boolean) (defaults to: false)


182
183
184
185
186
# File 'lib/mindee/input/sources.rb', line 182

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

Instance Method Details

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

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

Parameters:

  • close (Boolean) (defaults to: true)

Returns:

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


191
192
193
194
195
196
# File 'lib/mindee/input/sources.rb', line 191

def read_document(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