/
create-read.js
65 lines (56 loc) · 1.25 KB
/
create-read.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
61
62
63
64
65
module.exports = {
friendlyName: 'Create read',
description: 'Create a read stream',
extendedDescription: '',
sync: true,
inputs: {
"path": {
"friendlyName": "path",
"description": "A path file",
"example": 'tmp.log',
"required": false,
"type": "string",
"name": "path"
},
"text": {
"friendlyName": "text",
"description": "A text",
"example": 'lorem ipsum',
"required": false,
"type": "string",
"name": "text"
}
},
defaultExit: 'success',
exits: {
error: {
description: 'Unexpected error occurred.',
},
pathError: {
description: 'File does not exist.',
},
noStreamError: {
description: 'does not exist.',
},
success: {
"description": "Done."
},
},
fn: function (inputs,exits) {
var fs = require('fs'),
util = require('util');
if (inputs.path && !fs.existsSync(inputs.path))
return exits.pathError();
else if (!inputs.text)
inputs.text = '';
try {
return exits.success(
inputs.path
?
fs.createReadStream(inputs.path)
:
require('resumer')().queue(inputs.text).end()
);
} catch (err) { return exits.error(err); }
},
};