| Module | IOStream |
| In: |
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.
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 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.
# File 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