Guest User

Untitled

a guest
Jul 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. def download(target, options = {})
  2. case target
  3. when String
  4. modified = File.stat(target).mtime if File.exist?(target)
  5. temp = nil
  6. Tempfile.open(File.basename(target)) do |tf|
  7. tf.binmode
  8. read(options.merge(:modified => modified)) { |chunk| tf.write chunk }
  9. temp = tf
  10. end
  11. FileUtils.mkpath(File.dirname(target))
  12. FileUtils.move(temp.path, target)
  13. when File
  14. p options.merge(:modified => target.mtime)
  15. read(options.merge(:modified => target.mtime)) { |chunk| target.write chunk }
  16. target.flush
  17. else
  18. raise ArgumentError, "Expecting a target that is either a file name (string, task) or object that responds to write (file, pipe)." unless target.respond_to?(:write)
  19. read(options) { |chunk| target.write chunk }
  20. target.flush
  21. end
  22. end
Add Comment
Please, Sign In to add comment