mind-client-js 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +3 -0
- package/LICENSE +674 -0
- package/README.md +1 -0
- package/js/dynamic-pool.js +145 -0
- package/js/errors.js +84 -0
- package/js/extends/global.js +134 -0
- package/js/extends/glvn.js +940 -0
- package/js/extends/glvnManagement.js +76 -0
- package/js/index.js +811 -0
- package/js/login.js +215 -0
- package/js/namespaces/RESP3.js +211 -0
- package/js/namespaces/_staticPool.js +156 -0
- package/js/namespaces/db.js +23 -0
- package/js/namespaces/dbms.js +18 -0
- package/js/namespaces/fs.js +708 -0
- package/js/namespaces/globals.js +35 -0
- package/js/namespaces/process.js +451 -0
- package/js/namespaces/server.js +438 -0
- package/js/namespaces/session.js +622 -0
- package/js/namespaces/uApi.js +157 -0
- package/js/namespaces/vars.js +51 -0
- package/js/static-pool.js +789 -0
- package/js/uapi.js +270 -0
- package/js/utils.js +174 -0
- package/package.json +34 -0
- package/sketch.txt +22 -0
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
/*###############################################################
|
|
2
|
+
# #
|
|
3
|
+
# Copyright (c) 2025-2026 DnaSoft BV and/or its subsidiaries. #
|
|
4
|
+
# All rights reserved. #
|
|
5
|
+
# #
|
|
6
|
+
# This source code contains the intellectual property #
|
|
7
|
+
# of its copyright holder(s), and is made available #
|
|
8
|
+
# under a license. If you do not know the terms of #
|
|
9
|
+
# the license, please stop and do not read further. #
|
|
10
|
+
# #
|
|
11
|
+
###############################################################*/
|
|
12
|
+
|
|
13
|
+
const utils = require('../utils');
|
|
14
|
+
const errors = require('../errors.js')
|
|
15
|
+
|
|
16
|
+
class Fs {
|
|
17
|
+
// ************************************
|
|
18
|
+
// readFile
|
|
19
|
+
// ************************************
|
|
20
|
+
readFile = function (filename) {
|
|
21
|
+
const that = this
|
|
22
|
+
const RESP3 = that.objRoot.RESP3
|
|
23
|
+
|
|
24
|
+
return new Promise(function (resolve, reject) {
|
|
25
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
26
|
+
reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
|
|
27
|
+
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (filename === undefined) {
|
|
32
|
+
reject(new Error(errors.PARAM_MISSING + 'the filename has not been provided'))
|
|
33
|
+
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (utils.validateTypeOfField(filename, 'string') === false) {
|
|
38
|
+
reject(new Error(errors.PARAM_NOT_STRING + 'Parameter filename must be a string'))
|
|
39
|
+
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// send command
|
|
44
|
+
const opCode = 'fs.readFile'
|
|
45
|
+
that.writer("*2" + RESP3.CRLF +
|
|
46
|
+
RESP3.build.blob(opCode) +
|
|
47
|
+
RESP3.build.blob(filename)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
that.reader(data => {
|
|
51
|
+
if (data.charAt(0) === '-') {
|
|
52
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
53
|
+
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
resolve(RESP3.parse.blob(data))
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ************************************
|
|
63
|
+
// writeFile
|
|
64
|
+
// ************************************
|
|
65
|
+
writeFile = function (filename, data = '') {
|
|
66
|
+
const that = this
|
|
67
|
+
const RESP3 = that.objRoot.RESP3
|
|
68
|
+
|
|
69
|
+
return new Promise(function (resolve, reject) {
|
|
70
|
+
if (that.connected === false || that.loggedIn === false) {
|
|
71
|
+
reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
|
|
72
|
+
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (filename === undefined) {
|
|
77
|
+
reject(new Error(errors.FILENAME_NOT_PROVIDED + 'the filename has not been provided'))
|
|
78
|
+
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (utils.validateTypeOfField(filename, 'string') === false) {
|
|
83
|
+
reject(new Error(errors.PARAM_NOT_STRING + 'Parameter filename must be a string'))
|
|
84
|
+
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (utils.validateTypeOfField(data, 'string') === false) {
|
|
89
|
+
reject(new Error(errors.PARAM_NOT_STRING + 'Parameter data must be a string'))
|
|
90
|
+
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// send command
|
|
95
|
+
const opCode = 'fs.writeFile'
|
|
96
|
+
that.writer("*3" + RESP3.CRLF +
|
|
97
|
+
RESP3.build.blob(opCode) +
|
|
98
|
+
RESP3.build.blob(filename) +
|
|
99
|
+
RESP3.build.blob(data)
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
that.reader(data => {
|
|
103
|
+
if (data.charAt(0) === '-' || data.indexOf('+ok') === -1) {
|
|
104
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
105
|
+
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
resolve()
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ************************************
|
|
115
|
+
// appendFile
|
|
116
|
+
// ************************************
|
|
117
|
+
appendFile = function (filename, data = '') {
|
|
118
|
+
const that = this
|
|
119
|
+
const RESP3 = that.objRoot.RESP3
|
|
120
|
+
|
|
121
|
+
return new Promise(function (resolve, reject) {
|
|
122
|
+
if (that.connected === false || that.loggedIn === false) {
|
|
123
|
+
reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
|
|
124
|
+
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (filename === undefined) {
|
|
129
|
+
reject(new Error(errors.FILENAME_NOT_PROVIDED + 'the filename has not been provided'))
|
|
130
|
+
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (utils.validateTypeOfField(filename, 'string') === false) {
|
|
135
|
+
reject(new Error(errors.PARAM_NOT_STRING + 'Parameter filename must be a string'))
|
|
136
|
+
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (utils.validateTypeOfField(data, 'string') === false) {
|
|
141
|
+
reject(new Error(errors.PARAM_NOT_STRING + 'Parameter data must be a string'))
|
|
142
|
+
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// send command
|
|
147
|
+
const opCode = 'fs.appendFile'
|
|
148
|
+
that.writer("*3" + RESP3.CRLF +
|
|
149
|
+
RESP3.build.blob(opCode) +
|
|
150
|
+
RESP3.build.blob(filename) +
|
|
151
|
+
RESP3.build.blob(data)
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
that.reader(data => {
|
|
155
|
+
if (data.charAt(0) === '-' || data.indexOf('+ok') === -1) {
|
|
156
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
157
|
+
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
resolve()
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ************************************
|
|
167
|
+
// readDir
|
|
168
|
+
// ************************************
|
|
169
|
+
readDir = function (path, mask = '*') {
|
|
170
|
+
const that = this
|
|
171
|
+
const RESP3 = that.objRoot.RESP3
|
|
172
|
+
|
|
173
|
+
return new Promise(function (resolve, reject) {
|
|
174
|
+
if (that.connected === false || that.loggedIn === false) {
|
|
175
|
+
reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
|
|
176
|
+
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (path === undefined) {
|
|
181
|
+
reject(new Error(errors.PARAM_MISSING + 'the path has not been provided'))
|
|
182
|
+
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (utils.validateTypeOfField(path, 'string') === false) {
|
|
187
|
+
reject(new Error(errors.PARAM_NOT_STRING + 'Parameter path must be a string'))
|
|
188
|
+
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (utils.validateTypeOfField(mask, 'string') === false) {
|
|
193
|
+
reject(new Error(errors.PARAM_NOT_STRING + 'Parameter mask must be a string'))
|
|
194
|
+
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
// send command
|
|
198
|
+
const opCode = 'fs.readDir'
|
|
199
|
+
that.writer("*3" + RESP3.CRLF +
|
|
200
|
+
RESP3.build.blob(opCode) +
|
|
201
|
+
RESP3.build.blob(path) +
|
|
202
|
+
RESP3.build.blob(mask)
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
that.reader(data => {
|
|
206
|
+
if (data.charAt(0) === '-') {
|
|
207
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
208
|
+
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
resolve(RESP3.parse.blob(data).split(','))
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// ************************************
|
|
218
|
+
// readTree
|
|
219
|
+
// ************************************
|
|
220
|
+
readTree = function (path, mask = '*') {
|
|
221
|
+
const that = this
|
|
222
|
+
const RESP3 = that.objRoot.RESP3
|
|
223
|
+
|
|
224
|
+
return new Promise(function (resolve, reject) {
|
|
225
|
+
if (that.connected === false || that.loggedIn === false) {
|
|
226
|
+
reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
|
|
227
|
+
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (path === undefined) {
|
|
232
|
+
reject(new Error('the path has not been provided'))
|
|
233
|
+
|
|
234
|
+
return
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (utils.validateTypeOfField(path, 'string') === false) {
|
|
238
|
+
reject(new Error(errors.PARAM_NOT_STRING + 'Parameter path must be a string'))
|
|
239
|
+
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (utils.validateTypeOfField(mask, 'string') === false) {
|
|
244
|
+
reject(new Error(errors.PARAM_NOT_STRING + 'Parameter mask must be a string'))
|
|
245
|
+
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// send command
|
|
250
|
+
const opCode = 'fs.readTree'
|
|
251
|
+
that.writer("*3" + RESP3.CRLF +
|
|
252
|
+
RESP3.build.blob(opCode) +
|
|
253
|
+
RESP3.build.blob(path) +
|
|
254
|
+
RESP3.build.blob(mask)
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
that.reader(data => {
|
|
258
|
+
if (data.charAt(0) === '-') {
|
|
259
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
260
|
+
|
|
261
|
+
return
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
resolve(RESP3.parse.blob(data).split(','))
|
|
265
|
+
})
|
|
266
|
+
})
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// ************************************
|
|
270
|
+
// removeFile
|
|
271
|
+
// ************************************
|
|
272
|
+
removeFile = function (filename) {
|
|
273
|
+
const that = this
|
|
274
|
+
const RESP3 = that.objRoot.RESP3
|
|
275
|
+
|
|
276
|
+
return new Promise(function (resolve, reject) {
|
|
277
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
278
|
+
reject(new Error('Not logged in'))
|
|
279
|
+
|
|
280
|
+
return
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (filename === undefined) {
|
|
284
|
+
reject(new Error('the filename has not been provided'))
|
|
285
|
+
|
|
286
|
+
return
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (utils.validateTypeOfField(filename, 'string') === false) {
|
|
290
|
+
reject(new Error('Parameter filename must be a string'))
|
|
291
|
+
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// send command
|
|
296
|
+
const opCode = 'fs.removeFile'
|
|
297
|
+
that.writer("*2" + RESP3.CRLF +
|
|
298
|
+
RESP3.build.blob(opCode) +
|
|
299
|
+
RESP3.build.blob(filename)
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
that.reader(data => {
|
|
303
|
+
if (data.charAt(0) === '-') {
|
|
304
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
305
|
+
|
|
306
|
+
return
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
resolve()
|
|
310
|
+
})
|
|
311
|
+
})
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// ************************************
|
|
315
|
+
// renameFile
|
|
316
|
+
// ************************************
|
|
317
|
+
renameFile = function (filename, newFilename) {
|
|
318
|
+
const that = this
|
|
319
|
+
const RESP3 = that.objRoot.RESP3
|
|
320
|
+
|
|
321
|
+
return new Promise(function (resolve, reject) {
|
|
322
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
323
|
+
reject(new Error('Not logged in'))
|
|
324
|
+
|
|
325
|
+
return
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (filename === undefined) {
|
|
329
|
+
reject(new Error('the filename has not been provided'))
|
|
330
|
+
|
|
331
|
+
return
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (utils.validateTypeOfField(filename, 'string') === false) {
|
|
335
|
+
reject(new Error('Parameter filename must be a string'))
|
|
336
|
+
|
|
337
|
+
return
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (newFilename === undefined) {
|
|
341
|
+
reject(new Error('the newFilename has not been provided'))
|
|
342
|
+
|
|
343
|
+
return
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (utils.validateTypeOfField(newFilename, 'string') === false) {
|
|
347
|
+
reject(new Error('Parameter newFilename must be a string'))
|
|
348
|
+
|
|
349
|
+
return
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// send command
|
|
353
|
+
const opCode = 'fs.renameFile'
|
|
354
|
+
that.writer("*3" + RESP3.CRLF +
|
|
355
|
+
RESP3.build.blob(opCode) +
|
|
356
|
+
RESP3.build.blob(filename) +
|
|
357
|
+
RESP3.build.blob(newFilename)
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
that.reader(data => {
|
|
361
|
+
if (data.charAt(0) === '-') {
|
|
362
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
363
|
+
|
|
364
|
+
return
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
resolve()
|
|
368
|
+
})
|
|
369
|
+
})
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ************************************
|
|
373
|
+
// stat
|
|
374
|
+
// ************************************
|
|
375
|
+
stat = function (filename) {
|
|
376
|
+
const that = this
|
|
377
|
+
const RESP3 = that.objRoot.RESP3
|
|
378
|
+
|
|
379
|
+
return new Promise(function (resolve, reject) {
|
|
380
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
381
|
+
reject(new Error('Not logged in'))
|
|
382
|
+
|
|
383
|
+
return
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (filename === undefined) {
|
|
387
|
+
reject(new Error('the filename has not been provided'))
|
|
388
|
+
|
|
389
|
+
return
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (utils.validateTypeOfField(filename, 'string') === false) {
|
|
393
|
+
reject(new Error('Parameter filename must be a string'))
|
|
394
|
+
|
|
395
|
+
return
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// send command
|
|
399
|
+
const opCode = 'fs.stat'
|
|
400
|
+
that.writer("*2" + RESP3.CRLF +
|
|
401
|
+
RESP3.build.blob(opCode) +
|
|
402
|
+
RESP3.build.blob(filename)
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
that.reader(data => {
|
|
406
|
+
if (data.charAt(0) === '-') {
|
|
407
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
408
|
+
|
|
409
|
+
return
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
data = RESP3.parse.blob(data).split(RESP3.CRLF)
|
|
413
|
+
const res = {}
|
|
414
|
+
|
|
415
|
+
for (let ix = 0; ix < data.length; ix += 2) {
|
|
416
|
+
res[data[ix].slice(1)] = parseInt(data[ix + 1].slice(1))
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
resolve(res)
|
|
420
|
+
})
|
|
421
|
+
})
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// ************************************
|
|
425
|
+
// copyfile
|
|
426
|
+
// ************************************
|
|
427
|
+
copyfile = function (source, destination) {
|
|
428
|
+
const that = this
|
|
429
|
+
const RESP3 = that.objRoot.RESP3
|
|
430
|
+
|
|
431
|
+
return new Promise(function (resolve, reject) {
|
|
432
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
433
|
+
reject(new Error('Not logged in'))
|
|
434
|
+
|
|
435
|
+
return
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (source === undefined) {
|
|
439
|
+
reject(new Error('the source has not been provided'))
|
|
440
|
+
|
|
441
|
+
return
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (utils.validateTypeOfField(source, 'string') === false) {
|
|
445
|
+
reject(new Error('Parameter source must be a string'))
|
|
446
|
+
|
|
447
|
+
return
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (destination === undefined) {
|
|
451
|
+
reject(new Error('the destination has not been provided'))
|
|
452
|
+
|
|
453
|
+
return
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (utils.validateTypeOfField(destination, 'string') === false) {
|
|
457
|
+
reject(new Error('Parameter destination must be a string'))
|
|
458
|
+
|
|
459
|
+
return
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// send command
|
|
463
|
+
const opCode = 'fs.copyfile'
|
|
464
|
+
that.writer("*3" + RESP3.CRLF +
|
|
465
|
+
RESP3.build.blob(opCode) +
|
|
466
|
+
RESP3.build.blob(source) +
|
|
467
|
+
RESP3.build.blob(destination)
|
|
468
|
+
);
|
|
469
|
+
|
|
470
|
+
that.reader(data => {
|
|
471
|
+
if (data.charAt(0) === '-') {
|
|
472
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
473
|
+
|
|
474
|
+
return
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
resolve()
|
|
478
|
+
})
|
|
479
|
+
})
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// ************************************
|
|
483
|
+
// mkdir
|
|
484
|
+
// ************************************
|
|
485
|
+
mkdir = function (path) {
|
|
486
|
+
const that = this
|
|
487
|
+
const RESP3 = that.objRoot.RESP3
|
|
488
|
+
|
|
489
|
+
return new Promise(function (resolve, reject) {
|
|
490
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
491
|
+
reject(new Error('Not logged in'))
|
|
492
|
+
|
|
493
|
+
return
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (path === undefined) {
|
|
497
|
+
reject(new Error('the path has not been provided'))
|
|
498
|
+
|
|
499
|
+
return
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (utils.validateTypeOfField(path, 'string') === false) {
|
|
503
|
+
reject(new Error('Parameter path must be a string'))
|
|
504
|
+
|
|
505
|
+
return
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// send command
|
|
509
|
+
const opCode = 'fs.mkdir'
|
|
510
|
+
that.writer("*2" + RESP3.CRLF +
|
|
511
|
+
RESP3.build.blob(opCode) +
|
|
512
|
+
RESP3.build.blob(path)
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
that.reader(data => {
|
|
516
|
+
if (data.charAt(0) === '-') {
|
|
517
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
518
|
+
|
|
519
|
+
return
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
resolve()
|
|
523
|
+
})
|
|
524
|
+
})
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// ************************************
|
|
528
|
+
// expandPath
|
|
529
|
+
// ************************************
|
|
530
|
+
expandPath = function (path = '') {
|
|
531
|
+
const that = this
|
|
532
|
+
const RESP3 = that.objRoot.RESP3
|
|
533
|
+
|
|
534
|
+
return new Promise(function (resolve, reject) {
|
|
535
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
536
|
+
reject(new Error('Not logged in'))
|
|
537
|
+
|
|
538
|
+
return
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
if (path === undefined) {
|
|
542
|
+
reject(new Error('the path has not been provided'))
|
|
543
|
+
|
|
544
|
+
return
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (utils.validateTypeOfField(path, 'string') === false) {
|
|
548
|
+
reject(new Error('Parameter path must be a string'))
|
|
549
|
+
|
|
550
|
+
return
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// send command
|
|
554
|
+
const opCode = 'fs.expandPath'
|
|
555
|
+
that.writer("*2" + RESP3.CRLF +
|
|
556
|
+
RESP3.build.blob(opCode) +
|
|
557
|
+
RESP3.build.blob(path)
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
that.reader(data => {
|
|
561
|
+
if (data.charAt(0) === '-') {
|
|
562
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
563
|
+
|
|
564
|
+
return
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
resolve(RESP3.parse.simpleString(data))
|
|
568
|
+
})
|
|
569
|
+
})
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// ************************************
|
|
573
|
+
// rmdir
|
|
574
|
+
// ************************************
|
|
575
|
+
rmdir = function (path = '') {
|
|
576
|
+
const that = this
|
|
577
|
+
const RESP3 = that.objRoot.RESP3
|
|
578
|
+
|
|
579
|
+
return new Promise(function (resolve, reject) {
|
|
580
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
581
|
+
reject(new Error('Not logged in'))
|
|
582
|
+
|
|
583
|
+
return
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
if (path === undefined) {
|
|
587
|
+
reject(new Error('the path has not been provided'))
|
|
588
|
+
|
|
589
|
+
return
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (utils.validateTypeOfField(path, 'string') === false) {
|
|
593
|
+
reject(new Error('Parameter path must be a string'))
|
|
594
|
+
|
|
595
|
+
return
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// send command
|
|
599
|
+
const opCode = 'fs.rmdir'
|
|
600
|
+
that.writer("*2" + RESP3.CRLF +
|
|
601
|
+
RESP3.build.blob(opCode) +
|
|
602
|
+
RESP3.build.blob(path)
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
that.reader(data => {
|
|
606
|
+
if (data.charAt(0) === '-') {
|
|
607
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
608
|
+
|
|
609
|
+
return
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
resolve()
|
|
613
|
+
})
|
|
614
|
+
})
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// ************************************
|
|
618
|
+
// isDir
|
|
619
|
+
// ************************************
|
|
620
|
+
isDir = function (filename) {
|
|
621
|
+
const that = this
|
|
622
|
+
const RESP3 = that.objRoot.RESP3
|
|
623
|
+
|
|
624
|
+
return new Promise(function (resolve, reject) {
|
|
625
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
626
|
+
reject(new Error('Not logged in'))
|
|
627
|
+
|
|
628
|
+
return
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
if (filename === undefined) {
|
|
632
|
+
reject(new Error('the filename has not been provided'))
|
|
633
|
+
|
|
634
|
+
return
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (utils.validateTypeOfField(filename, 'string') === false) {
|
|
638
|
+
reject(new Error('Parameter filename must be a string'))
|
|
639
|
+
|
|
640
|
+
return
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// send command
|
|
644
|
+
const opCode = 'fs.isDir'
|
|
645
|
+
that.writer("*2" + RESP3.CRLF +
|
|
646
|
+
RESP3.build.blob(opCode) +
|
|
647
|
+
RESP3.build.blob(filename)
|
|
648
|
+
);
|
|
649
|
+
|
|
650
|
+
that.reader(data => {
|
|
651
|
+
if (data.charAt(0) === '-') {
|
|
652
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
653
|
+
|
|
654
|
+
return
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
resolve(RESP3.parse.boolean(data))
|
|
658
|
+
})
|
|
659
|
+
})
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// ************************************
|
|
663
|
+
// isFile
|
|
664
|
+
// ************************************
|
|
665
|
+
isFile = function (filename) {
|
|
666
|
+
const that = this
|
|
667
|
+
const RESP3 = that.objRoot.RESP3
|
|
668
|
+
|
|
669
|
+
return new Promise(function (resolve, reject) {
|
|
670
|
+
if (that.objRoot.connected === false || that.objRoot.loggedIn === false) {
|
|
671
|
+
reject(new Error('Not logged in'))
|
|
672
|
+
|
|
673
|
+
return
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
if (filename === undefined) {
|
|
677
|
+
reject(new Error('the filename has not been provided'))
|
|
678
|
+
|
|
679
|
+
return
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
if (utils.validateTypeOfField(filename, 'string') === false) {
|
|
683
|
+
reject(new Error('Parameter filename must be a string'))
|
|
684
|
+
|
|
685
|
+
return
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// send command
|
|
689
|
+
const opCode = 'fs.isFile'
|
|
690
|
+
that.writer("*2" + RESP3.CRLF +
|
|
691
|
+
RESP3.build.blob(opCode) +
|
|
692
|
+
RESP3.build.blob(filename)
|
|
693
|
+
);
|
|
694
|
+
|
|
695
|
+
that.reader(data => {
|
|
696
|
+
if (data.charAt(0) === '-') {
|
|
697
|
+
reject(new Error(RESP3.parse.simpleError(data)))
|
|
698
|
+
|
|
699
|
+
return
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
resolve(RESP3.parse.boolean(data))
|
|
703
|
+
})
|
|
704
|
+
})
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
module.exports = Fs
|