From 32565dc725928fafdad5c8eb06677f30548d6054 Mon Sep 17 00:00:00 2001 From: "Hemanth.HM" Date: Fri, 14 Oct 2016 19:11:43 +0530 Subject: [PATCH] Support URLs --- package.json | 6 ++++-- src/node/index.js | 14 +++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e56d22f..8136701 100644 --- a/package.json +++ b/package.json @@ -20,11 +20,13 @@ "browserify": "^13.1.0", "envify": "^3.4.1", "http-server": "^0.9.0", - "watchify": "^3.7.0", - "pako": "^1.0.3" + "pako": "^1.0.3", + "watchify": "^3.7.0" }, "dependencies": { "file-type": "^3.8.0", + "is-url": "^1.2.2", + "isomorphic-fetch": "^2.2.1", "jpeg-js": "^0.2.0", "level-js": "^2.2.4", "object-assign": "^4.1.0", diff --git a/src/node/index.js b/src/node/index.js index 0f6eed1..cc98988 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -1,4 +1,6 @@ const path = require('path') +const fetch = require('isomorphic-fetch') +const isURL = require('is-url') exports.defaultOptions = { workerPath: path.join(__dirname, 'worker.js'), @@ -29,7 +31,17 @@ exports.sendPacket = function sendPacket(instance, packet){ function loadImage(image, cb){ - // TODO: support URLs + + if(isURL(image) { + fetch(image).then(function (resp) { + return resp.buffer(); + }).then(function (buffer) { + return loadImage(buffer, cb); + }).catch(function (err) { + return console.error(err); + }); + }) + if(typeof image === 'string'){ fs.readFile(image, function(err, buffer){ if (err) throw err;