1/*
2 * Copyright (c) 2020 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "nativeapi_fs.h"
17#include <securec.h>
18#include <new>
19#include "ability_env.h"
20#include "js_async_work.h"
21#include "nativeapi_common.h"
22#include "nativeapi_fs_impl.h"
23
24namespace OHOS {
25namespace ACELite {
26namespace {
27char g_uriFullPath[FILE_NAME_MAX_LEN + 1] = {0};
28const unsigned int PREFIX_LEN = strlen(FILE_PREFIX);
29
30bool IsValidPath(const char* path)
31{
32    if (path == nullptr) {
33        return false;
34    }
35
36    size_t pathLen = strnlen(path, URI_NAME_MAX_LEN + 1);
37    if (pathLen > URI_NAME_MAX_LEN) {
38        return false;
39    }
40    if ((pathLen < PREFIX_LEN) || (strncmp(path, FILE_PREFIX, PREFIX_LEN) != 0)) {
41        return false;
42    }
43    if ((strstr(path, "/./") != nullptr) || (strstr(path, "/../") != nullptr)) {
44        return false;
45    }
46    if (strpbrk(path + PREFIX_LEN, "\"*+,:;<=>\?[]|\x7F")) {
47        return false;
48    }
49    return true;
50}
51
52int GetFullPath(const char* uri, char* fullPath, int len)
53{
54    if (!IsValidPath(uri) || (fullPath == nullptr)) {
55        return ERROR_CODE_PARAM;
56    }
57    const char* dataPath = GetDataPath();
58    if (dataPath == nullptr) {
59        return ERROR_CODE_PARAM;
60    }
61    if (memset_s(fullPath, len, 0x0, len) != EOK) {
62        return ERROR_CODE_GENERAL;
63    }
64    if (sprintf_s(fullPath, len, "%s%s", dataPath, uri + PREFIX_LEN) < 0) {
65        return ERROR_CODE_GENERAL;
66    }
67    return NATIVE_SUCCESS;
68}
69
70JSIValue ExecuteAsyncWork(const JSIValue thisVal, const JSIValue* args,
71    uint8_t argsNum, AsyncWorkHandler ExecuteFunc, bool flag = false)
72{
73    JSIValue undefValue = JSI::CreateUndefined();
74    if (!NativeapiCommon::IsValidJSIValue(args, argsNum)) {
75        return undefValue;
76    }
77    FuncParams* params = new(std::nothrow) FuncParams();
78    if (params == nullptr) {
79        return undefValue;
80    }
81    params->thisVal = JSI::AcquireValue(thisVal);
82    params->args = JSI::AcquireValue(args[0]);
83    params->flag = flag;
84    JsAsyncWork::DispatchAsyncWork(ExecuteFunc, reinterpret_cast<void *>(params));
85    return undefValue;
86}
87
88void ExecuteCopyFile(void* data)
89{
90    FuncParams* params = reinterpret_cast<FuncParams *>(data);
91    if (params == nullptr) {
92        return;
93    }
94    JSIValue args = params->args;
95    JSIValue thisVal = params->thisVal;
96    char* src = JSI::GetStringProperty(args, FILE_SOURCE_URI);
97    char* dest = JSI::GetStringProperty(args, FILE_DESTINATION_URI);
98    char* destFullPath = nullptr;
99    JSIValue result = JSI::CreateUndefined();
100    int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
101    JSI::ReleaseString(src);
102    if (ret != NATIVE_SUCCESS) {
103        NativeapiCommon::FailCallBack(thisVal, args, ret);
104        goto EXIT;
105    }
106    destFullPath = reinterpret_cast<char *>(malloc(FILE_NAME_MAX_LEN + 1));
107    if (destFullPath == nullptr) {
108        NativeapiCommon::FailCallBack(thisVal, args, ERROR_CODE_GENERAL);
109        goto EXIT;
110    }
111    ret = GetFullPath(dest, destFullPath, FILE_NAME_MAX_LEN + 1);
112    if (ret != NATIVE_SUCCESS) {
113        NativeapiCommon::FailCallBack(thisVal, args, ret);
114        goto EXIT;
115    }
116    ret = CopyFileImpl(g_uriFullPath, destFullPath);
117    if (ret != NATIVE_SUCCESS) {
118        NativeapiCommon::FailCallBack(thisVal, args, ret);
119        goto EXIT;
120    }
121    if (params->flag) {
122        ret = DeleteFileImpl(g_uriFullPath);
123    }
124    if (ret != NATIVE_SUCCESS) {
125        NativeapiCommon::FailCallBack(thisVal, args, ret);
126        goto EXIT;
127    }
128    result = JSI::CreateString(dest);
129    NativeapiCommon::SuccessCallBack(thisVal, args, result);
130EXIT:
131    JSI::ReleaseString(dest);
132    free(destFullPath);
133    JSI::ReleaseValueList(args, thisVal, result, ARGS_END);
134    delete params;
135}
136
137void ExecuteDeleteAccess(void* data)
138{
139    FuncParams* params = reinterpret_cast<FuncParams *>(data);
140    if (params == nullptr) {
141        return;
142    }
143    JSIValue args = params->args;
144    JSIValue thisVal = params->thisVal;
145    char* src = JSI::GetStringProperty(args, FILE_URI);
146    int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
147    JSI::ReleaseString(src);
148    if (ret != NATIVE_SUCCESS) {
149        NativeapiCommon::FailCallBack(thisVal, args, ret);
150        goto EXIT;
151    }
152    if (params->flag) {
153        ret = DeleteFileImpl(g_uriFullPath);
154    } else {
155        ret = AccessImpl(g_uriFullPath);
156    }
157    if (ret != NATIVE_SUCCESS) {
158        NativeapiCommon::FailCallBack(thisVal, args, ret);
159        goto EXIT;
160    }
161    NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined());
162EXIT:
163    JSI::ReleaseValueList(args, thisVal, ARGS_END);
164    delete params;
165}
166
167int GetFileListInner(const char* path, const char* key, JSIValue& result)
168{
169    int fileNum = GetFileNum(g_uriFullPath);
170    if (fileNum <= 0) {
171        return fileNum;
172    }
173    FileMetaInfo* fileList = reinterpret_cast<FileMetaInfo *>(malloc(fileNum * sizeof(FileMetaInfo)));
174    if (fileList == nullptr) {
175        return ERROR_CODE_GENERAL;
176    }
177    if (memset_s(fileList, fileNum * sizeof(FileMetaInfo), 0x0, fileNum * sizeof(FileMetaInfo)) != EOK) {
178        free(fileList);
179        return ERROR_CODE_GENERAL;
180    }
181    int ret = GetFileListImpl(g_uriFullPath, fileList, fileNum);
182    if (ret != NATIVE_SUCCESS) {
183        free(fileList);
184        return ret;
185    }
186    JSIValue arrayValue = JSI::CreateArray(fileNum);
187    for (int i = 0; i < fileNum; i++) {
188        JSIValue tmp = JSI::CreateObject();
189        JSI::SetStringProperty(tmp, FILE_URI, fileList[i].fileName);
190        JSI::SetNumberProperty(tmp, FILE_LENGTH, fileList[i].fileSize);
191        JSI::SetNumberProperty(tmp, FILE_LAST_MODIFIED_TIME, fileList[i].fileMtime);
192        JSI::SetStringProperty(tmp, FILE_TYPE, TYPE_FILE);
193        if (S_ISDIR(fileList[i].fileMode)) {
194            JSI::SetStringProperty(tmp, FILE_TYPE, TYPE_DIR);
195        }
196        JSI::SetPropertyByIndex(arrayValue, i, tmp);
197        JSI::ReleaseValue(tmp);
198    }
199    free(fileList);
200    JSI::SetNamedProperty(result, key, arrayValue);
201    JSI::ReleaseValue(arrayValue);
202    return NATIVE_SUCCESS;
203}
204
205void ExecuteGetFileList(void* data)
206{
207    FuncParams* params = reinterpret_cast<FuncParams *>(data);
208    if (params == nullptr) {
209        return;
210    }
211    JSIValue args = params->args;
212    JSIValue thisVal = params->thisVal;
213    char* uri = JSI::GetStringProperty(args, FILE_URI);
214    JSIValue result = JSI::CreateObject();
215    int ret = GetFullPath(uri, g_uriFullPath, sizeof(g_uriFullPath));
216    JSI::ReleaseString(uri);
217    if (ret != NATIVE_SUCCESS) {
218        NativeapiCommon::FailCallBack(thisVal, args, ret);
219        goto EXIT;
220    }
221    if (params->flag) {
222        ret = GetFileListInner(g_uriFullPath, FILE_LIST, result);
223    } else {
224        ret = GetFileListInner(g_uriFullPath, SUB_FILES, result);
225    }
226    if (ret != NATIVE_SUCCESS) {
227        NativeapiCommon::FailCallBack(thisVal, args, ret);
228        goto EXIT;
229    }
230    NativeapiCommon::SuccessCallBack(thisVal, args, result);
231EXIT:
232    JSI::ReleaseValueList(args, thisVal, result, ARGS_END);
233    delete params;
234}
235
236void ExecuteGetFileInfo(void* data)
237{
238    FuncParams* params = reinterpret_cast<FuncParams *>(data);
239    if (params == nullptr) {
240        return;
241    }
242    JSIValue args = params->args;
243    JSIValue thisVal = params->thisVal;
244    char* src = JSI::GetStringProperty(args, FILE_URI);
245    bool recursive = JSI::GetBooleanProperty(args, RECURSIVE);
246    struct stat info = {0};
247    JSIValue result = JSI::CreateObject();
248    int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
249    if (ret != NATIVE_SUCCESS) {
250        NativeapiCommon::FailCallBack(thisVal, args, ret);
251        goto EXIT;
252    }
253    ret = StatImpl(g_uriFullPath, &info);
254    if (ret != NATIVE_SUCCESS) {
255        NativeapiCommon::FailCallBack(thisVal, args, ret);
256        goto EXIT;
257    }
258    if (recursive && (S_ISDIR(info.st_mode))) {
259        JSI::ReleaseString(src);
260        ExecuteGetFileList(data);
261        return;
262    }
263    JSI::SetStringProperty(result, FILE_URI, src);
264    JSI::SetNumberProperty(result, FILE_LENGTH, info.st_size);
265    JSI::SetNumberProperty(result, FILE_LAST_MODIFIED_TIME, info.st_mtime);
266    JSI::SetStringProperty(result, FILE_TYPE, TYPE_FILE);
267    if (S_ISDIR(info.st_mode)) {
268        JSI::SetStringProperty(result, FILE_TYPE, TYPE_DIR);
269    }
270    NativeapiCommon::SuccessCallBack(thisVal, args, result);
271EXIT:
272    JSI::ReleaseString(src);
273    JSI::ReleaseValueList(args, thisVal, result, ARGS_END);
274    delete params;
275}
276
277void ExecuteWriteTextFile(void* data)
278{
279    FuncParams* params = reinterpret_cast<FuncParams *>(data);
280    if (params == nullptr) {
281        return;
282    }
283    JSIValue args = params->args;
284    JSIValue thisVal = params->thisVal;
285    char* src = JSI::GetStringProperty(args, FILE_URI);
286    char* text = JSI::GetStringProperty(args, TEXT);
287    bool append = JSI::GetBooleanProperty(args, FILE_APPEND);
288    int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
289    JSI::ReleaseString(src);
290    if ((text == nullptr) || (ret != NATIVE_SUCCESS)) {
291        NativeapiCommon::FailCallBack(thisVal, args, ERROR_CODE_PARAM);
292        goto EXIT;
293    }
294    ret = WriteTextFile(g_uriFullPath, text, strlen(text), append);
295    if (ret != NATIVE_SUCCESS) {
296        NativeapiCommon::FailCallBack(thisVal, args, ret);
297        goto EXIT;
298    }
299    NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined());
300EXIT:
301    JSI::ReleaseString(text);
302    JSI::ReleaseValueList(args, thisVal, ARGS_END);
303    delete params;
304}
305
306int ReadTextInner(const char* src, int position, int length, JSIValue& result)
307{
308    if ((position < 0) || (length < 0)) {
309        return ERROR_CODE_PARAM;
310    }
311    if (length == 0) {
312        length = TEXT_MAX_READ_LEN;
313    }
314    int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
315    if (ret != NATIVE_SUCCESS) {
316        return ret;
317    }
318    struct stat info = {0};
319    ret = StatImpl(g_uriFullPath, &info);
320    if (ret != NATIVE_SUCCESS) {
321        return ret;
322    }
323    size_t readLen = (info.st_size > length) ? length : info.st_size;
324    if (readLen > TEXT_MAX_READ_LEN) {
325        return ERROR_CODE_READ_TOO_LONG;
326    }
327    char* text = reinterpret_cast<char *>(malloc(readLen + 1));
328    if (text == nullptr) {
329        return ERROR_CODE_GENERAL;
330    }
331    size_t actualLen = 0;
332    ret = ReadFileImpl(g_uriFullPath, text, readLen, position, &actualLen);
333    if (ret != NATIVE_SUCCESS) {
334        free(text);
335        return ret;
336    }
337    text[actualLen] = '\0';
338    JSI::SetStringProperty(result, TEXT, text);
339    free(text);
340    return NATIVE_SUCCESS;
341}
342
343void ExecuteReadTextFile(void* data)
344{
345    FuncParams* params = reinterpret_cast<FuncParams *>(data);
346    if (params == nullptr) {
347        return;
348    }
349    JSIValue args = params->args;
350    JSIValue thisVal = params->thisVal;
351    char* src = JSI::GetStringProperty(args, FILE_URI);
352    double position = JSI::GetNumberProperty(args, FILE_POSITION);
353    double length = JSI::GetNumberProperty(args, FILE_LENGTH);
354    JSIValue result = JSI::CreateObject();
355    int ret = ReadTextInner(src, static_cast<int>(position), static_cast<int>(length), result);
356    JSI::ReleaseString(src);
357    if (ret == NATIVE_SUCCESS) {
358        NativeapiCommon::SuccessCallBack(thisVal, args, result);
359    } else {
360        NativeapiCommon::FailCallBack(thisVal, args, ret);
361    }
362    JSI::ReleaseValueList(args, thisVal, result, ARGS_END);
363    delete params;
364}
365
366void ExecuteDirFunc(void* data)
367{
368    FuncParams* params = reinterpret_cast<FuncParams *>(data);
369    if (params == nullptr) {
370        return;
371    }
372    JSIValue args = params->args;
373    JSIValue thisVal = params->thisVal;
374    char* src = JSI::GetStringProperty(args, FILE_URI);
375    int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
376    JSI::ReleaseString(src);
377    bool recursive = JSI::GetBooleanProperty(args, RECURSIVE);
378    if (ret != NATIVE_SUCCESS) {
379        NativeapiCommon::FailCallBack(thisVal, args, ret);
380        goto EXIT;
381    }
382    if (params->flag) {
383        ret = CreateDirImpl(g_uriFullPath, recursive);
384    } else {
385        ret = RemoveDirImpl(g_uriFullPath, recursive);
386    }
387    if (ret != NATIVE_SUCCESS) {
388        NativeapiCommon::FailCallBack(thisVal, args, ret);
389        goto EXIT;
390    }
391    NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined());
392EXIT:
393    JSI::ReleaseValueList(args, thisVal, ARGS_END);
394    delete params;
395}
396#if (JS_FWK_TYPEDARRAY == NATIVE_FEATURE_ON)
397int ReadArrayFileInner(const char* path, size_t len, unsigned int position, JSIValue& result)
398{
399    struct stat info = {0};
400    int ret = StatImpl(path, &info);
401    if (ret != NATIVE_SUCCESS) {
402        return ret;
403    }
404    void* text = malloc(info.st_size + 1);
405    if (text == nullptr) {
406        return ERROR_CODE_GENERAL;
407    }
408    size_t actualLen = 0;
409    ret = ReadFileImpl(path, text, len, static_cast<int>(position), &actualLen);
410    if (ret != NATIVE_SUCCESS) {
411        free(text);
412        return ret;
413    }
414    uint8_t* ptr = nullptr;
415    JSIValue arrayBuffer = JSI::CreateArrayBuffer(actualLen, ptr);
416    if (ptr == nullptr) {
417        free(text);
418        JSI::ReleaseValue(arrayBuffer);
419        return ERROR_CODE_GENERAL;
420    }
421    ret = memcpy_s(ptr, actualLen, text, actualLen);
422    free(text);
423    if (ret != EOK) {
424        JSI::ReleaseValue(arrayBuffer);
425        return ERROR_CODE_GENERAL;
426    }
427    JSIValue typedArray = JSI::CreateTypedArray(TypedArrayType::JSI_UINT8_ARRAY, actualLen, arrayBuffer, 0);
428    JSI::SetNamedProperty(result, FILE_BUFFER, typedArray);
429    JSI::ReleaseValueList(typedArray, arrayBuffer, ARGS_END);
430    return NATIVE_SUCCESS;
431}
432
433void ExecuteReadArrayFile(void* data)
434{
435    FuncParams* params = reinterpret_cast<FuncParams *>(data);
436    if (params == nullptr) {
437        return;
438    }
439    JSIValue args = params->args;
440    JSIValue thisVal = params->thisVal;
441    char* src = JSI::GetStringProperty(args, FILE_URI);
442    double position = JSI::GetNumberProperty(args, FILE_POSITION);
443    double length = JSI::GetNumberProperty(args, FILE_LENGTH);
444    JSIValue result = JSI::CreateObject();
445    int ret = ERROR_CODE_PARAM;
446    if ((position < 0) || (length < 0)) {
447        JSI::ReleaseString(src);
448        NativeapiCommon::FailCallBack(thisVal, args, ret);
449        goto EXIT;
450    }
451    ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
452    JSI::ReleaseString(src);
453    if (ret != NATIVE_SUCCESS) {
454        NativeapiCommon::FailCallBack(thisVal, args, ret);
455        goto EXIT;
456    }
457    ret = ReadArrayFileInner(g_uriFullPath, static_cast<int>(length), static_cast<int>(position), result);
458    if (ret != NATIVE_SUCCESS) {
459        NativeapiCommon::FailCallBack(thisVal, args, ret);
460        goto EXIT;
461    }
462    NativeapiCommon::SuccessCallBack(thisVal, args, result);
463EXIT:
464    JSI::ReleaseValueList(args, thisVal, result, ARGS_END);
465    delete params;
466}
467
468void ExecuteWriteArrayFile(void* data)
469{
470    FuncParams* params = reinterpret_cast<FuncParams *>(data);
471    if (params == nullptr) {
472        return;
473    }
474    JSIValue args = params->args;
475    JSIValue thisVal = params->thisVal;
476    char* src = JSI::GetStringProperty(args, FILE_URI);
477    int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
478    JSI::ReleaseString(src);
479    if (ret != NATIVE_SUCCESS) {
480        NativeapiCommon::FailCallBack(thisVal, args, ret);
481        JSI::ReleaseValueList(args, thisVal, ARGS_END);
482        delete params;
483        return;
484    }
485    JSIValue buffer = JSI::GetNamedProperty(args, FILE_BUFFER);
486    double position = JSI::GetNumberProperty(args, FILE_POSITION);
487    bool append = JSI::GetBooleanProperty(args, FILE_APPEND);
488    TypedArrayType type = TypedArrayType::JSI_INVALID_ARRAY;
489    size_t length = 0;
490    JSIValue arrayBuffer = JSI::CreateUndefined();
491    size_t byteOffset = 0;
492    uint8_t* arrayPtr = JSI::GetTypedArrayInfo(buffer, type, length, arrayBuffer, byteOffset);
493    ret = ERROR_CODE_PARAM;
494    if ((position < 0) || (arrayPtr == nullptr) || (type != TypedArrayType::JSI_UINT8_ARRAY)) {
495        JSI::ReleaseValueList(buffer, arrayBuffer, ARGS_END);
496        NativeapiCommon::FailCallBack(thisVal, args, ERROR_CODE_PARAM);
497        goto EXIT;
498    }
499    ret = WriteArrayFile(g_uriFullPath, arrayPtr, length, static_cast<int>(position), append);
500    JSI::ReleaseValueList(buffer, arrayBuffer, ARGS_END);
501    if (ret != NATIVE_SUCCESS) {
502        NativeapiCommon::FailCallBack(thisVal, args, ret);
503        goto EXIT;
504    }
505    NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined());
506EXIT:
507    JSI::ReleaseValueList(args, thisVal, ARGS_END);
508    delete params;
509}
510#endif
511}
512
513void InitNativeApiFs(JSIValue exports)
514{
515    JSI::SetModuleAPI(exports, "move", NativeapiFs::MoveFile);
516    JSI::SetModuleAPI(exports, "copy", NativeapiFs::CopyFile);
517    JSI::SetModuleAPI(exports, "delete", NativeapiFs::DeleteFile);
518    JSI::SetModuleAPI(exports, "list", NativeapiFs::GetFileList);
519    JSI::SetModuleAPI(exports, "get", NativeapiFs::GetFileInfo);
520    JSI::SetModuleAPI(exports, "readText", NativeapiFs::ReadTextFile);
521    JSI::SetModuleAPI(exports, "writeText", NativeapiFs::WriteTextFile);
522    JSI::SetModuleAPI(exports, "access", NativeapiFs::Access);
523    JSI::SetModuleAPI(exports, "mkdir", NativeapiFs::CreateDir);
524    JSI::SetModuleAPI(exports, "rmdir", NativeapiFs::RemoveDir);
525
526#if (JS_FWK_TYPEDARRAY == NATIVE_FEATURE_ON)
527    JSI::SetModuleAPI(exports, "readArrayBuffer", NativeapiFs::ReadArrayFile);
528    JSI::SetModuleAPI(exports, "writeArrayBuffer", NativeapiFs::WriteArrayFile);
529#endif
530}
531
532JSIValue NativeapiFs::MoveFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
533{
534    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteCopyFile, true);
535}
536
537JSIValue NativeapiFs::CopyFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
538{
539    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteCopyFile);
540}
541
542JSIValue NativeapiFs::DeleteFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
543{
544    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteDeleteAccess, true);
545}
546
547JSIValue NativeapiFs::GetFileList(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
548{
549    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetFileList, true);
550}
551
552JSIValue NativeapiFs::GetFileInfo(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
553{
554    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetFileInfo);
555}
556
557JSIValue NativeapiFs::WriteTextFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
558{
559    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteWriteTextFile);
560}
561
562JSIValue NativeapiFs::ReadTextFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
563{
564    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteReadTextFile);
565}
566
567JSIValue NativeapiFs::Access(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
568{
569    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteDeleteAccess);
570}
571
572JSIValue NativeapiFs::CreateDir(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
573{
574    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteDirFunc, true);
575}
576
577JSIValue NativeapiFs::RemoveDir(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
578{
579    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteDirFunc);
580}
581
582#if (JS_FWK_TYPEDARRAY == NATIVE_FEATURE_ON)
583JSIValue NativeapiFs::ReadArrayFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
584{
585    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteReadArrayFile);
586}
587
588JSIValue NativeapiFs::WriteArrayFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
589{
590    return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteWriteArrayFile);
591}
592#endif
593} // ACELite
594} // OHOS
595