Permalink
Browse files

Update Curl file structure.

  • Loading branch information...
1 parent 1057195 commit 2c414d1469a3d9cec2ed07a4429332607b04bfaf @jiangmiao committed Feb 19, 2013
Showing with 41 additions and 99 deletions.
  1. +2 −1 index.toffee
  2. +15 −4 lib/{curl.toffee → Curl.toffee}
  3. +10 −9 lib/CurlBuilder.js
  4. +8 −5 lib/CurlBuilder.toffee
  5. +6 −0 lib/CurlInstance.js
  6. +0 −80 lib/curl.js
View
@@ -1 +1,2 @@
-module.exports = require './lib/curl'
+CurlBuilder = require './lib/CurlBuilder'
+module.exports = CurlBuilder.create()
@@ -3,8 +3,6 @@ try
catch e
{Curl} = require __dirname + '/../build/default/node-curl'
-CurlBuilder = require __dirname + '/CurlBuilder'
-
Curl::setopt_user_ = (option_id, value) ->
@options[option_id] = value
@@ -41,6 +39,18 @@ 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()
@@ -56,5 +66,6 @@ Curl.process = ->
else
Curl.in_process = false
-curl = CurlBuilder.create()
-module.exports = curl
+
+module.exports = Curl
+# vim: sw=2 ts=2 sts=2 expandtab :
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,7 +1,7 @@
try
- {Curl} = require __dirname + '/../build/Release/node-curl'
+ Curl = require __dirname + '/Curl'
catch e
- {Curl} = require __dirname + '/../build/default/node-curl'
+ Curl = require __dirname + '/Curl'
class CurlBuilder
@curls: {}
@@ -47,12 +47,13 @@ class CurlBuilder
@setOptions @effectiveOptions
@setOptions {URL: @url}
- c.on_write = (chunk) ->
+ c.on 'data', (chunk) ->
curl.log "receive #{chunk.length} bytes"
c.chunks.push chunk
length += chunk.length
+ chunk.length
- c.on_end = ->
+ c.on 'end', ->
curl.log "receive succeeded."
curl.running = false
data = new Buffer(length)
@@ -72,7 +73,7 @@ class CurlBuilder
process.nextTick!
cb.call curl, null, curl
- c.on_error = (err)->
+ c.on 'error', (err)->
curl.log "receive failed: #{err.message}"
curl.running = false
process.nextTick!
@@ -146,3 +147,5 @@ process.on 'exit', ->
CurlBuilder.close_all()
module.exports = CurlBuilder
+
+# vim: sw=2 ts=2 sts=2 expandtab :
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 2c414d1

Please sign in to comment.