Module: SimpleImagesDownloader::StringioToTempfile

Defined in:
lib/simple_images_downloader/stringio_to_tempfile.rb

Overview

StringIOToTempfile module Responsible for converting StringIO to Tempfile

# => #<Tempfile:0x00007f9b9c0b3a38>

Examples:

SimpleImagesDownloader::StringioToTempfile.convert(stringio)

Class Method Summary collapse

Class Method Details

.convert(stringio) ⇒ Tempfile

Returns Tempfile object.

Parameters:

  • stringio (StringIO)

    StringIO object

Returns:

  • (Tempfile)

    Tempfile object



16
17
18
19
20
21
22
23
24
# File 'lib/simple_images_downloader/stringio_to_tempfile.rb', line 16

def convert(stringio)
  tempfile = Tempfile.new(binmode: true)

  IO.copy_stream(stringio, tempfile)

  OpenURI::Meta.init tempfile, stringio

  tempfile
end