forked from roccomuso/upx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 831 Bytes
/
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
import * as fs from 'fs'
import * as upxBin from './lib/upxBin.js'
import * as opts2Args from './lib/opts2Args.js'
class Upx {
constructor (file, opts) {
fileExists(file)
this.file = file
this.opts = opts || {}
}
output (outPath) {
this._output = outPath
return this
}
start () {
let self = this
return new Promise(function (resolve, reject) {
upxBin.default.call(self, opts2Args.default(self.opts), function (err, stats) {
if (err) return reject(err)
resolve(stats)
})
})
}
}
export default function (file, opts) {
return new Upx(file, opts)
}
function fileExists (file) {
try {
fs.statSync(file)
} catch (e) {
throw Error('Make sure the file exists: ' + file + ' ERROR ' + e)
}
}