From 0e0aa8ceaf4d635a83353c27b76d93115e962d8c Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Fri, 12 Feb 2016 13:16:21 +0200 Subject: [PATCH] File exists for ios optimized --- file-system/file-system-access.ios.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/file-system/file-system-access.ios.ts b/file-system/file-system-access.ios.ts index e7cd964a8..8cc10c3f9 100644 --- a/file-system/file-system-access.ios.ts +++ b/file-system/file-system-access.ios.ts @@ -147,17 +147,21 @@ export class FileSystemAccess { } public fileExists(path: string): boolean { - var fileManager = NSFileManager.defaultManager(); - return fileManager.fileExistsAtPath(path) && !this.folderExists(path); + var result = this.exists(path); + return result.exists && !result.isDirectory; } public folderExists(path: string): boolean { + var result = this.exists(path); + return result.exists && result.isDirectory; + } + + private exists(path: string): { exists: boolean, isDirectory: boolean } { var fileManager = NSFileManager.defaultManager(); + var isDirectory = new interop.Reference(interop.types.bool, false); + var exists = fileManager.fileExistsAtPathIsDirectory(path, isDirectory); - var outVal = new interop.Reference(); - var exists = fileManager.fileExistsAtPathIsDirectory(path, outVal); - - return exists && outVal.value > 0; + return { exists: exists, isDirectory: isDirectory.value }; } public concatPath(left: string, right: string): string { @@ -245,7 +249,7 @@ export class FileSystemAccess { } } - public read(path: string, onError?: (error: any) => any) : NSData { + public read(path: string, onError?: (error: any) => any): NSData { try { return NSData.dataWithContentsOfFile(path); }