Skip to content

Instantly share code, notes, and snippets.

@rkachowski
Created May 25, 2012 12:40
Show Gist options
  • Save rkachowski/2787832 to your computer and use it in GitHub Desktop.
Save rkachowski/2787832 to your computer and use it in GitHub Desktop.
nodejs downloader
http = require 'http'
fs = require 'fs'
URL = require 'url'
class Downloader
@download_image:(image_url, destination, callback)
options = URL.parse image_url
http.get(options, (response) ->
fileStream = false
response.on 'data', (data_chunk) ->
fileStream = fs.createWriteStream(destination) unless fileStream?
fileStream.write data_chunk
response.on 'end', () ->
fileStream.end()
console.log "downloaded #{image_url}!"
callback()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment