Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def download(target, options = {})
- case target
- when String
- modified = File.stat(target).mtime if File.exist?(target)
- temp = nil
- Tempfile.open(File.basename(target)) do |tf|
- tf.binmode
- read(options.merge(:modified => modified)) { |chunk| tf.write chunk }
- temp = tf
- end
- FileUtils.mkpath(File.dirname(target))
- FileUtils.move(temp.path, target)
- when File
- p options.merge(:modified => target.mtime)
- read(options.merge(:modified => target.mtime)) { |chunk| target.write chunk }
- target.flush
- else
- 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)
- read(options) { |chunk| target.write chunk }
- target.flush
- end
- end
Add Comment
Please, Sign In to add comment