Class: Mindee::Input::Source::Base64InputSource
- Inherits:
-
LocalInputSource
- Object
- LocalInputSource
- Mindee::Input::Source::Base64InputSource
- 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
-
#initialize(base64_string, filename, fix_pdf: false) ⇒ Base64InputSource
constructor
A new instance of Base64InputSource.
-
#read_document(close: true) ⇒ Array<String, [String, aBinaryString ], [Hash, nil] >
Overload of the same function to prevent a base64 from being re-encoded.
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.
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.
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 |