aboutsummaryrefslogtreecommitdiff
path: root/node_modules/superagent/lib/node/parsers
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/superagent/lib/node/parsers')
-rw-r--r--node_modules/superagent/lib/node/parsers/image.js10
-rw-r--r--node_modules/superagent/lib/node/parsers/index.js8
-rw-r--r--node_modules/superagent/lib/node/parsers/json.js19
-rw-r--r--node_modules/superagent/lib/node/parsers/text.js7
-rw-r--r--node_modules/superagent/lib/node/parsers/urlencoded.js19
5 files changed, 63 insertions, 0 deletions
diff --git a/node_modules/superagent/lib/node/parsers/image.js b/node_modules/superagent/lib/node/parsers/image.js
new file mode 100644
index 0000000..b3e0ebc
--- /dev/null
+++ b/node_modules/superagent/lib/node/parsers/image.js
@@ -0,0 +1,10 @@
+module.exports = function(res, fn){
+ var data = []; // Binary data needs binary storage
+
+ res.on('data', function(chunk){
+ data.push(chunk);
+ });
+ res.on('end', function () {
+ fn(null, Buffer.concat(data));
+ });
+}; \ No newline at end of file
diff --git a/node_modules/superagent/lib/node/parsers/index.js b/node_modules/superagent/lib/node/parsers/index.js
new file mode 100644
index 0000000..b6f4bf6
--- /dev/null
+++ b/node_modules/superagent/lib/node/parsers/index.js
@@ -0,0 +1,8 @@
+
+exports['application/x-www-form-urlencoded'] = require('./urlencoded');
+exports['application/json'] = require('./json');
+exports.text = require('./text');
+
+var binary = require('./image');
+exports['application/octet-stream'] = binary;
+exports.image = binary;
diff --git a/node_modules/superagent/lib/node/parsers/json.js b/node_modules/superagent/lib/node/parsers/json.js
new file mode 100644
index 0000000..b71662d
--- /dev/null
+++ b/node_modules/superagent/lib/node/parsers/json.js
@@ -0,0 +1,19 @@
+
+module.exports = function parseJSON(res, fn){
+ res.text = '';
+ res.setEncoding('utf8');
+ res.on('data', function(chunk){ res.text += chunk;});
+ res.on('end', function(){
+ try {
+ var body = res.text && JSON.parse(res.text);
+ } catch (e) {
+ var err = e;
+ // issue #675: return the raw response if the response parsing fails
+ err.rawResponse = res.text || null;
+ // issue #876: return the http status code if the response parsing fails
+ err.statusCode = res.statusCode;
+ } finally {
+ fn(err, body);
+ }
+ });
+};
diff --git a/node_modules/superagent/lib/node/parsers/text.js b/node_modules/superagent/lib/node/parsers/text.js
new file mode 100644
index 0000000..03575c6
--- /dev/null
+++ b/node_modules/superagent/lib/node/parsers/text.js
@@ -0,0 +1,7 @@
+
+module.exports = function(res, fn){
+ res.text = '';
+ res.setEncoding('utf8');
+ res.on('data', function(chunk){ res.text += chunk; });
+ res.on('end', fn);
+}; \ No newline at end of file
diff --git a/node_modules/superagent/lib/node/parsers/urlencoded.js b/node_modules/superagent/lib/node/parsers/urlencoded.js
new file mode 100644
index 0000000..245c665
--- /dev/null
+++ b/node_modules/superagent/lib/node/parsers/urlencoded.js
@@ -0,0 +1,19 @@
+
+/**
+ * Module dependencies.
+ */
+
+var qs = require('qs');
+
+module.exports = function(res, fn){
+ res.text = '';
+ res.setEncoding('ascii');
+ res.on('data', function(chunk){ res.text += chunk; });
+ res.on('end', function(){
+ try {
+ fn(null, qs.parse(res.text));
+ } catch (err) {
+ fn(err);
+ }
+ });
+}; \ No newline at end of file