Module | IOStream
In: | vendor/plugins/paperclip/lib/paperclip/iostream.rb

Provides method that can be included on File-type objects (IO, StringIO, Tempfile, etc) to allow stream copying and Tempfile conversion.

### Methods

stream_to to_tempfile

### Public Instance methods

stream_to(path_or_file, in_blocks_of = 8192)

Copies one read-able object from one place to another in blocks, obviating the need to load the whole thing into memory. Defaults to 8k blocks. If this module is included in both StringIO and Tempfile, then either can have its data copied anywhere else without typing worries or memory overhead worries. Returns a File if a String is passed in as the destination and returns the IO or Tempfile as passed in if one is sent as the destination.

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/iostream.rb, line 17
    17:   def stream_to path_or_file, in_blocks_of = 8192
    18:     dstio = case path_or_file
    19:             when String   then File.new(path_or_file, "wb+")
    20:             when IO       then path_or_file
    21:             when Tempfile then path_or_file
    22:             end
    23:     buffer = ""
    24:     self.rewind
    25:     while self.read(in_blocks_of, buffer) do
    26:       dstio.write(buffer)
    27:     end
    28:     dstio.rewind
    29:     dstio
    30:   end

to_tempfile()

Returns a Tempfile containing the contents of the readable object.

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/iostream.rb, line 6
     6:   def to_tempfile
     7:     tempfile = Tempfile.new("stream")
     8:     tempfile.binmode
     9:     self.stream_to(tempfile)
    10:   end

[Validate]