Skip to content

Commit 56d7f91

Browse files
authored
fix:修复使用isDir方法返回undefined的问题 (#16)
1 parent 355b867 commit 56d7f91

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

codegenSpecs/NativeBlobUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface Spec extends TurboModule {
3333
+createFileASCII: (path: string, data: Array<any>) => Promise<void>;
3434
+pathForAppGroup: (groupName: string) => Promise<string>;
3535
+syncPathAppGroup: (groupName: string) => string;
36-
+exists: (path: string, callback: (value: Array<boolean>) => void) => void;
36+
+exists: (path: string, callback: (value:boolean,isDir?:boolean) => void) => void;
3737
+writeFile: (path: string, encoding: string, data: string, transformFile: boolean, append: boolean) => Promise<number>;
3838
+writeFileArray: (path: string, data: Array<any>, append: boolean) => Promise<number>;
3939
+writeStream: (path: string, withEncoding: string, appendData: boolean, callback: (value: Array<any>) => void) => void;

harmony/blobUtil/src/main/ets/BlobUtilTurboModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class BlobUtilTurboModule extends TurboModule {
9494
this.reactNativeBlobUtilImpl.writeArrayChunk(streamId,withArray,callback)
9595
}
9696

97-
exists(path: string, callback: (value: boolean) => void){
97+
exists(path: string, callback: (value: boolean,isDir?:boolean) => void){
9898
this.reactNativeBlobUtilImpl.exists(path,callback)
9999
}
100100

harmony/blobUtil/src/main/ets/ReactNativeBlobUtil/ReactNativeBlobUtilFS.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,21 @@ export default class ReactNativeBlobUtilFS {
246246
})
247247
}
248248

249-
exists(path: string, callback: (value: boolean) => void) {
249+
exists(path: string, callback: (value: boolean, isDir?: boolean) => void) {
250250
return new Promise((resolve, reject) => {
251-
fs.access(path, (err: BusinessError, result: boolean) => {
251+
fs.stat(path, (err: BusinessError, res: fs.Stat) => {
252252
if (err) {
253253
reject('File does not exist');
254254
} else {
255-
callback(result);
255+
fs.access(path, (err: BusinessError, result: boolean) => {
256+
if (err) {
257+
reject('File does not exist');
258+
} else {
259+
callback(result, res.isDirectory());
260+
}
261+
});
256262
}
257-
});
263+
})
258264
})
259265
};
260266

harmony/blobUtil/src/main/ets/ReactNativeBlobUtil/ReactNativeBlobUtilImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default class ReactNativeBlobUtilImpl {
109109
this.reactNativeBlobUtilStream.writeArrayChunk(streamId, withArray, callback)
110110
}
111111

112-
exists(path: string, callback: (value: boolean) => void) {
112+
exists(path: string, callback: (value: boolean,isDir?:boolean) => void) {
113113
this.reactNativeBlobUtilFS.exists(path, callback)
114114
}
115115

0 commit comments

Comments
 (0)