Update Curl file structure.

This commit is contained in:
Miao Jiang 2013-02-19 17:30:16 +08:00
parent 1057195bf5
commit 2c414d1469
6 changed files with 41 additions and 99 deletions

View file

@ -1 +1,2 @@
module.exports = require './lib/curl'
CurlBuilder = require './lib/CurlBuilder'
module.exports = CurlBuilder.create()

View file

@ -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 file

@ -5,9 +5,9 @@
__slice = [].slice;
try {
Curl = require(__dirname + '/../build/Release/node-curl').Curl;
Curl = require(__dirname + '/Curl');
} catch (e) {
Curl = require(__dirname + '/../build/default/node-curl').Curl;
Curl = require(__dirname + '/Curl');
}
CurlBuilder = (function() {
@ -69,12 +69,13 @@
this.setOptions({
URL: this.url
});
c.on_write = function(chunk) {
c.on('data', function(chunk) {
curl.log("receive " + chunk.length + " bytes");
c.chunks.push(chunk);
return length += chunk.length;
};
c.on_end = function() {
length += chunk.length;
return chunk.length;
});
c.on('end', function() {
var chunk, data, position, _i, _len, _ref5,
_this = this;
curl.log("receive succeeded.");
@ -97,15 +98,15 @@
return process.nextTick(function() {
return cb.call(curl, null, curl);
});
};
c.on_error = function(err) {
});
c.on('error', function(err) {
var _this = this;
curl.log("receive failed: " + err.message);
curl.running = false;
return process.nextTick(function() {
return cb.call(curl, err, null);
});
};
});
this.log('perform');
return c.perform();
};

View file

@ -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 :

6
lib/CurlInstance.js Normal file
View file

@ -0,0 +1,6 @@
// Generated by ToffeeScript 1.4.0
(function() {
}).call(this);

View file

@ -1,80 +0,0 @@
// Generated by ToffeeScript 1.4.0
(function() {
var Curl, CurlBuilder, curl;
try {
Curl = require(__dirname + '/../build/Release/node-curl').Curl;
} catch (e) {
Curl = require(__dirname + '/../build/default/node-curl').Curl;
}
CurlBuilder = require(__dirname + '/CurlBuilder');
Curl.prototype.setopt_user_ = function(option_id, value) {
return this.options[option_id] = value;
};
Curl.prototype.setopt = function(ooption, value) {
var option, option_id;
option = ooption.toUpperCase();
if ((option_id = Curl.user_options[option]) != null) {
return this.setopt_user_(option_id, value);
} else if ((option_id = Curl.slist_options[option]) != null) {
return this.setopt_slist_(option_id, value);
} else if ((option_id = Curl.integer_options[option]) != null) {
return this.setopt_int_(option_id, value >> 0);
} else if ((option_id = Curl.string_options[option]) != null) {
return this.setopt_str_(option_id, value.toString());
} else {
throw new Error("unsupported option " + option);
}
};
Curl.prototype.getinfo = function(oinfo) {
var info, info_id;
info = oinfo.toUpperCase();
if ((info_id = Curl.slist_infos[info]) != null) {
return this.getinfo_slist_(info_id);
} else if ((info_id = Curl.integer_infos[info]) != null) {
return this.getinfo_int_(info_id);
} else if ((info_id = Curl.string_infos[info]) != null) {
return this.getinfo_str_(info_id);
} else if ((info_id = Curl.double_infos[info]) != null) {
return this.getinfo_double_(info_id);
} else {
throw new Error("unsupported info " + oinfo);
}
};
Curl.user_options = {
RAW: 'RAW',
DEBUG: 'DEBUG'
};
Curl.prototype.perform = function() {
this.perform_();
return Curl.process();
};
Curl.process = function() {
var once;
if (Curl.in_process) {
return;
}
return (once = function() {
var num;
num = Curl.process_();
if (num > 0) {
Curl.in_process = true;
return setTimeout(once, 80);
} else {
return Curl.in_process = false;
}
})();
};
curl = CurlBuilder.create();
module.exports = curl;
}).call(this);