Created
October 18, 2015 01:33
-
-
Save itsmemattchung/5fa9d6cf8102204ea363 to your computer and use it in GitHub Desktop.
Promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sumologic module | |
* @module lib/sumologic | |
*/ | |
var rsvp = require('rsvp'); | |
var fs = require('fs'); | |
var request = require('request') | |
var util = require('util'); | |
var upload = function(filename, url){ | |
var options = { | |
headers: { | |
'Content-Encoding': 'gzip' | |
}, | |
url: url | |
} | |
return new rsvp.Promise(function(resolve, reject){ | |
fs.createReadStream(filename).pipe( | |
request | |
.post(options) | |
.on('response', function(response){ | |
if(response.statusCode != 200){ | |
reject(new Error(util.format("Unable to upload file %s to %s", filename, url))); | |
} | |
resolve(response); | |
}) | |
); | |
}) | |
} | |
module.exports = { | |
/** Upload a gzip encoded file to sumologic http collector **/ | |
upload: upload | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment