try {Curl} = require __dirname + '/../build/Release/node-curl' catch e {Curl} = require __dirname + '/../build/default/node-curl' Curl::setopt_user_ = (option_id, value) -> @options[option_id] = value Curl::setopt = (ooption, value) -> option = ooption.toUpperCase() # slist must be at the top of condition # the option exists in string_options too if (option_id = Curl.user_options[option])? @setopt_user_ option_id, value else if (option_id = Curl.slist_options[option])? @setopt_slist_ option_id, value else if (option_id = Curl.integer_options[option])? @setopt_int_ option_id, value >> 0 else if (option_id = Curl.string_options[option])? @setopt_str_ option_id, value.toString() else throw new Error("unsupported option #{option}") Curl::getinfo = (oinfo) -> info = oinfo.toUpperCase() if (info_id = Curl.slist_infos[info])? @getinfo_slist_(info_id) else if (info_id = Curl.integer_infos[info])? @getinfo_int_(info_id) else if (info_id = Curl.string_infos[info])? @getinfo_str_(info_id) else if (info_id = Curl.double_infos[info])? @getinfo_double_(info_id) else throw new Error("unsupported info #{oinfo}") Curl.user_options = RAW: 'RAW' DEBUG: 'DEBUG' Curl::on = (event, callback) -> switch event when 'data' @on_write = callback when 'error' @on_error = callback when 'end' @on_end = callback else throw new Error("invalid event type #{event}") @ Curl::perform = -> @perform_() Curl.process() Curl.process = -> if Curl.in_process return do once = -> num = Curl.process_() if num > 0 Curl.in_process = true setTimeout once, 80 else Curl.in_process = false module.exports = Curl # vim: sw=2 ts=2 sts=2 expandtab :