/
decrypt-stream-file.js
60 lines (50 loc) · 1.29 KB
/
decrypt-stream-file.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
57
58
59
60
module.exports = {
friendlyName: 'Decrypt stream file',
description: 'Decrypt a streamfile with source path',
extendedDescription: '',
inputs: {
path: {
example: 'file.txt.gz',
description: 'a path',
required: true
},
secret: {
example: 'a secure phrase or password',
description: 'a secure phrase',
required: true
},
save: {
example: true,
description: 'a boolean, saving in the same folder',
required: false
}
},
defaultExit: 'success',
exits: {
error: {
description: 'Unexpected error occurred.',
},
errorFileNotFind: {
description: 'Error: File not find.',
},
success: {
description: 'Done.',
},
},
fn: function (inputs,exits) {
var helper = require("../lib/helper.js");
var fs = require("fs");
if (fs.existsSync(inputs.path) !== true)
return exits.errorFileNotFind();
var stream = helper.decryptStream(fs.createReadStream(inputs.path), inputs.secret);
if (inputs.save){
var newPath = inputs.path.slice(0, -3);
console.log("newPath",newPath);
stream.pipe(fs.createWriteStream(newPath));
}
return exits.success({
stream: stream,
path: inputs.save ? inputs.path.slice(0, -3) : inputs.path
});
},
};