From 05b8345650a62a629765e2ba1060c1c02dae77ca Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Sat, 25 May 2013 16:19:07 +0800 Subject: [PATCH] Update README. --- README.md | 18 ++++++++++++++---- examples/low-level.js | 15 +++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bd0547d..4f0d5dc 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ Quick Start console.info(this.info('SIZE_DOWNLOAD')); }); - * with options curl = require('node-curl') @@ -43,6 +42,7 @@ Usage members: status - Http Response code body - Http body + header - Http header url - the url set by curl(...) options - the options set by curl(...) @@ -52,6 +52,10 @@ Usage methods: 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 members @@ -139,6 +143,7 @@ Methods: Events: 'data', function(Buffer chunk) {} + 'header', function(Buffer chunk) {} 'error', function(Error error) {} 'end', function() {} @@ -159,21 +164,26 @@ Example: examples/low-level.js // on 'data' must be returns chunk.length, or means interrupt the transfer curl.on('data', function(chunk) { - p("receive " + chunk.length) + p("receive " + 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) { - p("error: " + e.message) + p("error: " + e.message); curl.close(); }); curl.on('end', function() { p('code: ' + curl.getinfo('RESPONSE_CODE')); - p('done.') + p('done.'); curl.close(); }); diff --git a/examples/low-level.js b/examples/low-level.js index 43baa87..7af236a 100644 --- a/examples/low-level.js +++ b/examples/low-level.js @@ -1,4 +1,4 @@ -var Curl = require('../lib/Curl') +var Curl = require('../lib/Curl'); var p = console.log; 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 curl.on('data', function(chunk) { - p("receive " + chunk.length) + p("receive " + 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) { p("error: " + e.message); curl.close(); @@ -25,9 +32,9 @@ curl.on('error', function(e) { curl.on('end', function() { - p("code: " + curl.getinfo('RESPONSE_CODE')); - curl.close(); + p('code: ' + curl.getinfo('RESPONSE_CODE')); p('done.'); + curl.close(); }); curl.perform();