Method: HTTPX::Response::Body#copy_to
- Defined in:
- lib/httpx/response/body.rb
permalink #copy_to(dest) ⇒ Object
copies the payload to dest
.
body.copy_to("path/to/file")
body.copy_to(Pathname.new("path/to/file"))
body.copy_to(File.new("path/to/file"))
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/httpx/response/body.rb', line 128 def copy_to(dest) return unless @buffer rewind if dest.respond_to?(:path) && @buffer.respond_to?(:path) FileUtils.mv(@buffer.path, dest.path) else ::IO.copy_stream(@buffer, dest) end end |