-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadFile.js
More file actions
42 lines (31 loc) · 1.05 KB
/
DownloadFile.js
File metadata and controls
42 lines (31 loc) · 1.05 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
37
38
39
40
41
42
require('dotenv').config();
const fs = require('fs');
const util = require('util')
splitSync = require('node-split').splitSync;
let {isValidToken} = require('./tokenValidation.js');
let {login} = require('./login.js');
async function DownloadFile(call) {
let validationResponseObject = await isValidToken();
var validationResponse = validationResponseObject.isValid;
console.log("validationResponse download file-->",validationResponse);
if (!validationResponse){
await login();
console.log("login function");
}
var filePath = process.env.LOCAL_PATH;
var data = fs.readFileSync(filePath + call.request.filename);
var buffArr = splitSync(data, {
bytes: '20K' // 20 * 1024 bytes per files
});
try {
buffArr.forEach(buffer => {
call.write({ payload: buffer });
});
call.end();
} catch (error) {
call.write({ error: 'No such file or directory: ' + error });
console.error(error);
call.end();
}
}
exports.DownloadFile = DownloadFile;