-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
56 lines (47 loc) · 1.88 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* File: index.js (node-lepton)
* Project: Node-Lepton
* Date: July 2016.
*
* Description: This npm module provides a wrapper for using Dropbox's Lepton in Nodejs code
*/
(function(){
var exec = require('child_process').exec,
fs = require('fs');
var node_lepton = {
compress: function( sourceFile, options, callback){
var generatedFile = Math.random().toString(36).slice(2)+".lep";
exec( "lepton -memory=1024M -threadmemory=128M " + sourceFile + " " + generatedFile, function (error, stdout, stderr) {
if (error) {
console.error('exec error: ' + error);
return callback(error, null);
}
fs.readFile(generatedFile, function(error, file_binary_data){
if(error) return callback(error, null);
fs.unlink(generatedFile, function(err){
if(err) return callback(err, null);
return callback(null, file_binary_data);
});
});
});
},
decompress: function( sourceFile, options, callback){
var generatedFile = Math.random().toString(36).slice(2)+".jpeg";
exec( "lepton -memory=1024M -threadmemory=128M " + sourceFile + " " + generatedFile, function (error, stdout, stderr) {
if (error) {
console.error('exec error: ' + error);
return callback(error, null);
}
fs.readFile(generatedFile, function(error, file_binary_data){
if(error) return callback(error, null);
fs.unlink(generatedFile, function(err){
if(err) return callback(err, null);
return callback(null, file_binary_data);
});
});
return callback(null, error);
});
},
};
module.exports = node_lepton;
}())