diff --git a/.gitignore b/.gitignore index 73b62e6..eb298e0 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ node_modules .lock-wscript *.jpg +!test/test.jpg diff --git a/index.js b/index.js index 63439df..d946171 100644 --- a/index.js +++ b/index.js @@ -28,18 +28,13 @@ var base64encoder = function (url, options, callback) { if (options && options.localFile === true) { fs.readFile(url, function (err, data) { - if (err) { - return callback(err); - } + if (err) { return callback(err); } return encoder(data, options); }); - } - else { + } else { request({url: url, encoding: null}, function (err, res, body) { - if (err) { - return callback(err); - } + if (err) { return callback(err); } if (body && res.statusCode === 200) { return encoder(body, options); @@ -54,9 +49,7 @@ var base64decoder = function (imageBuffer, options, callback) { if (options && options.filename) { fs.writeFile(options.filename + '.jpg', imageBuffer, 'base64', function (err) { - if (err) { - return callback(err); - } + if (err) { return callback(err); } return callback(null, 'Image saved successfully to disk!'); }); } diff --git a/test/test.jpg b/test/test.jpg new file mode 100644 index 0000000..fac43c0 Binary files /dev/null and b/test/test.jpg differ diff --git a/test/tests.js b/test/tests.js index dab621a..fcef8ae 100644 --- a/test/tests.js +++ b/test/tests.js @@ -67,7 +67,7 @@ describe('Image download and encode/decode to Base64', function () { it('should use a local image and return base64 encoded Buffer', function (done) { this.timeout(15000); - var path = __dirname + '/../test.jpg', + var path = __dirname + '/test.jpg', options = {localFile: true}; base64Image.base64encoder(path, options, function (err, image) { @@ -83,7 +83,7 @@ describe('Image download and encode/decode to Base64', function () { it('should use a local image and return base64 encoded string', function (done) { this.timeout(15000); - var path = __dirname + '/../test.jpg', + var path = __dirname + '/test.jpg', options = {localFile: true, string: true}; base64Image.base64encoder(path, options, function (err, image) {