Comparing version 1.0.3 to 1.0.4
var exec = require('child_process').exec; | ||
var tmp = require('tmp'); | ||
var fs = require('fs'); | ||
var http = require('http'); | ||
var tmp = require('tmp'); | ||
var filesource = require('filesource'); | ||
@@ -43,5 +43,11 @@ var initialized = false; | ||
var execute = function() { | ||
filesource.getDataPath(filepathOrData, function(resp){ | ||
if(!resp.success) | ||
{ | ||
callback(resp); | ||
return; | ||
} | ||
// get temporary filepath | ||
tmp.file({ postfix: ".png" }, function (err, imageFilepath, fd) { | ||
tmp.file({ postfix: ".png" }, function(err, imageFilepath, fd) { | ||
if(err) | ||
@@ -53,5 +59,5 @@ { | ||
exec("gs -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -sDEVICE=png16m -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r" + options.quality + " -dFirstPage=1 -dLastPage=1 -sOutputFile=" + imageFilepath + " " + filepathOrData, function (error, stdout, stderr) { | ||
// Remove temp file | ||
if(tmpFileCreated) fs.unlink(filepathOrData); | ||
exec("gs -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -sDEVICE=png16m -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r" + options.quality + " -dFirstPage=1 -dLastPage=1 -sOutputFile=" + imageFilepath + " " + resp.data, function (error, stdout, stderr) { | ||
// Remove temp files | ||
resp.clean(); | ||
@@ -78,60 +84,3 @@ if(error !== null) | ||
}); | ||
}; | ||
if(typeof(filepathOrData) == "object") | ||
{ | ||
tmpFileCreated = true; | ||
var fileData = filepathOrData; | ||
// get temporary filepath | ||
tmp.file({ postfix: ".pdf" }, function (err, path, fd) { | ||
if(err) | ||
{ | ||
callback({ success: false, error: "Error getting first temporary filepath: " + err }); | ||
return; | ||
} | ||
fs.writeFile(path, fileData, function(err) { | ||
if(err) | ||
{ | ||
callback({ success: false, error: "Error saving given binary filedata to file: " + err }); | ||
return; | ||
} | ||
// set filepath | ||
filepathOrData = path; | ||
// Execute | ||
execute(); | ||
}); | ||
}); | ||
} | ||
else if(filepathOrData.substr(0, 7) == "http://" || filepathOrData.substr(0, 8) == "https://") | ||
{ | ||
tmpFileCreated = true; | ||
// get temporary filepath | ||
tmp.file({ postfix: ".pdf" }, function (err, path, fd) { | ||
if(err) | ||
{ | ||
callback({ success: false, error: "Error getting first temporary filepath: " + err }); | ||
return; | ||
} | ||
var file = fs.createWriteStream(path); | ||
var request = http.get(filepathOrData, function(response) { | ||
response.pipe(file); | ||
response.on('end', function () { | ||
// set filepath | ||
filepathOrData = path; | ||
// Execute | ||
execute(); | ||
}); | ||
}); | ||
}); | ||
} | ||
else execute(); | ||
}); | ||
}; |
{ | ||
"name": "pdf2png", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Takes a PDF-document and converts and delivers a PNG", | ||
@@ -8,3 +8,4 @@ "engine": "node >= 0.6.0", | ||
"devDependencies": { | ||
"tmp": "0.0.23" | ||
"tmp": "0.0.23", | ||
"filesource": "latest" | ||
}, | ||
@@ -11,0 +12,0 @@ "repository" : |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
2
11402449
2
157