Update README.

This commit is contained in:
Miao Jiang 2013-05-25 16:19:07 +08:00
parent f02c0a6fbf
commit 05b8345650
2 changed files with 25 additions and 8 deletions

View file

@ -17,7 +17,6 @@ Quick Start
console.info(this.info('SIZE_DOWNLOAD')); console.info(this.info('SIZE_DOWNLOAD'));
}); });
* with options * with options
curl = require('node-curl') curl = require('node-curl')
@ -43,6 +42,7 @@ Usage
members: members:
status - Http Response code status - Http Response code
body - Http body body - Http body
header - Http header
url - the url set by curl(...) url - the url set by curl(...)
options - the options set by curl(...) options - the options set by curl(...)
@ -52,6 +52,10 @@ Usage
methods: methods:
info(name) - Get information of result, see 'info' section info(name) - Get information of result, see 'info' section
REMARK:
If the http is redirected, then header will contain at least 2 http headers.
* Curl Control * Curl Control
members members
@ -139,6 +143,7 @@ Methods:
Events: Events:
'data', function(Buffer chunk) {} 'data', function(Buffer chunk) {}
'header', function(Buffer chunk) {}
'error', function(Error error) {} 'error', function(Error error) {}
'end', function() {} 'end', function() {}
@ -159,21 +164,26 @@ Example: examples/low-level.js
// on 'data' must be returns chunk.length, or means interrupt the transfer // on 'data' must be returns chunk.length, or means interrupt the transfer
curl.on('data', function(chunk) { curl.on('data', function(chunk) {
p("receive " + chunk.length) p("receive " + chunk.length);
return chunk.length; return chunk.length;
}); });
curl.on('header', function(chunk) {
p("receive header " + chunk.length);
return chunk.length;
})
// curl.close() should be called in event 'error' and 'end' if the curl won't use any more. // curl.close() should be called in event 'error' and 'end' if the curl won't use any more.
// or the resource will not release until V8 garbage mark sweep. // or the resource will not release until V8 garbage mark sweep.
curl.on('error', function(e) { curl.on('error', function(e) {
p("error: " + e.message) p("error: " + e.message);
curl.close(); curl.close();
}); });
curl.on('end', function() { curl.on('end', function() {
p('code: ' + curl.getinfo('RESPONSE_CODE')); p('code: ' + curl.getinfo('RESPONSE_CODE'));
p('done.') p('done.');
curl.close(); curl.close();
}); });

View file

@ -1,4 +1,4 @@
var Curl = require('../lib/Curl') var Curl = require('../lib/Curl');
var p = console.log; var p = console.log;
var url = process.argv[2]; var url = process.argv[2];
@ -14,10 +14,17 @@ curl.setopt('VERBOSE', 1);
// on 'data' must be returns chunk.length, or means interrupt the transfer // on 'data' must be returns chunk.length, or means interrupt the transfer
curl.on('data', function(chunk) { curl.on('data', function(chunk) {
p("receive " + chunk.length) p("receive " + chunk.length);
return chunk.length; return chunk.length;
}); });
curl.on('header', function(chunk) {
p("receive header " + chunk.length);
return chunk.length;
})
// curl.close() should be called in event 'error' and 'end' if the curl won't use any more.
// or the resource will not release until V8 garbage mark sweep.
curl.on('error', function(e) { curl.on('error', function(e) {
p("error: " + e.message); p("error: " + e.message);
curl.close(); curl.close();
@ -25,9 +32,9 @@ curl.on('error', function(e) {
curl.on('end', function() { curl.on('end', function() {
p("code: " + curl.getinfo('RESPONSE_CODE')); p('code: ' + curl.getinfo('RESPONSE_CODE'));
curl.close();
p('done.'); p('done.');
curl.close();
}); });
curl.perform(); curl.perform();