Browse Source

Support URLs

pull/34/head
Hemanth.HM 8 years ago
parent
commit
32565dc725
  1. 6
      package.json
  2. 14
      src/node/index.js

6
package.json

@ -20,11 +20,13 @@ @@ -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",

14
src/node/index.js

@ -1,4 +1,6 @@ @@ -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){ @@ -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;

Loading…
Cancel
Save