forked from shebinleo/pdf2html
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostinstall.js
More file actions
36 lines (33 loc) · 1.19 KB
/
postinstall.js
File metadata and controls
36 lines (33 loc) · 1.19 KB
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
const http = require('http')
const fs = require('fs')
const constants = require('./constants')
const dependencies = {
[constants.VENDOR_PDF_BOX_JAR]: 'http://archive.apache.org/dist/pdfbox/2.0.16/pdfbox-app-2.0.16.jar',
[constants.VENDOR_TIKA_JAR]: 'http://archive.apache.org/dist/tika/tika-app-1.22.jar'
}
const download = (filename) => {
const filePath = constants.DIRECTORY.VENDOR + filename
fs.access(filePath, fs.constants.F_OK, (err) => {
if (err) {
console.log(`Started downloading dependency ${filename}.`)
const request = http.get(dependencies[filename], (response) => {
if (response.statusCode === 200) {
const fileStream = fs.createWriteStream(filePath)
response.pipe(fileStream)
fileStream.addListener('finish', () => {
console.log(`Finished downloading dependency ${filename}.`)
})
} else {
throw new Error(`Failed downloading dependency ${filename}.`)
}
})
request.on('error', () => {
throw new Error(`Failed downloading dependency ${filename}.`)
})
}
})
}
const filenames = Object.keys(dependencies)
filenames.forEach((filename) => {
download(filename)
})