mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Modified some FileSystem APIs as per the review documents.
This commit is contained in:
6
FileSystem/file_system.d.ts
vendored
6
FileSystem/file_system.d.ts
vendored
@ -102,16 +102,16 @@ export declare class Folder extends FileSystemEntity {
|
||||
/**
|
||||
* Provides access to the top-level Folders instances that are accessible from the application. Use these as entry points to access the FileSystem.
|
||||
*/
|
||||
export declare class KnownFolders {
|
||||
export declare module knownFolders {
|
||||
/**
|
||||
* Gets the Documents folder available for the current application. This Folder is private for the application and not accessible from Users/External apps.
|
||||
*/
|
||||
public static documents(): Folder;
|
||||
export function documents(): Folder;
|
||||
|
||||
/**
|
||||
* Gets the Temporary (Caches) folder available for the current application. This Folder is private for the application and not accessible from Users/External apps.
|
||||
*/
|
||||
public static temporary(): Folder;
|
||||
export function temp(): Folder;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,12 +29,12 @@ var createFile = function (info: { path: string; name: string; extension: string
|
||||
};
|
||||
|
||||
var createFolder = function (info: { path: string; name: string; }) {
|
||||
var documents = KnownFolders.documents();
|
||||
var documents = knownFolders.documents();
|
||||
if (info.path === documents.path) {
|
||||
return documents;
|
||||
}
|
||||
|
||||
var temp = KnownFolders.temporary();
|
||||
var temp = knownFolders.temp();
|
||||
if (info.path === temp.path) {
|
||||
return temp;
|
||||
}
|
||||
@ -160,6 +160,7 @@ export class File extends FileSystemEntity {
|
||||
|
||||
return createFile(fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a File with the specified path already exists.
|
||||
*/
|
||||
@ -174,6 +175,7 @@ export class File extends FileSystemEntity {
|
||||
this.checkAccess();
|
||||
return new FileReader(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a FileWriter object over this file and locks the file until the writer is released.
|
||||
*/
|
||||
@ -181,12 +183,14 @@ export class File extends FileSystemEntity {
|
||||
this.checkAccess();
|
||||
return new FileWriter(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extension of the entity.
|
||||
*/
|
||||
get extension(): string {
|
||||
return this[extensionProperty];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether the file is currently locked, meaning a background operation associated with this file is running.
|
||||
*/
|
||||
@ -317,36 +321,36 @@ export class Folder extends FileSystemEntity {
|
||||
/**
|
||||
* Provides access to the top-level Folders instances that are accessible from the application. Use these as entry points to access the FileSystem.
|
||||
*/
|
||||
export class KnownFolders {
|
||||
private static _documents: Folder;
|
||||
private static _temp: Folder;
|
||||
export module knownFolders {
|
||||
var _documents: Folder;
|
||||
var _temp: Folder;
|
||||
|
||||
/**
|
||||
* Gets the Documents folder available for the current application. This Folder is private for the application and not accessible from Users/External apps.
|
||||
*/
|
||||
public static documents(): Folder {
|
||||
if (!KnownFolders._documents) {
|
||||
export var documents = function (): Folder {
|
||||
if (!_documents) {
|
||||
var path = getFileAccess().getDocumentsFolderPath();
|
||||
KnownFolders._documents = new Folder();
|
||||
KnownFolders._documents[pathProperty] = path;
|
||||
KnownFolders._documents[isKnownProperty] = true;
|
||||
_documents = new Folder();
|
||||
_documents[pathProperty] = path;
|
||||
_documents[isKnownProperty] = true;
|
||||
}
|
||||
|
||||
return KnownFolders._documents;
|
||||
}
|
||||
return _documents;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the Temporary (Caches) folder available for the current application. This Folder is private for the application and not accessible from Users/External apps.
|
||||
*/
|
||||
public static temporary(): Folder {
|
||||
if (!KnownFolders._temp) {
|
||||
export var temp = function (): Folder {
|
||||
if (!_temp) {
|
||||
var path = getFileAccess().getTempFolderPath();
|
||||
KnownFolders._temp = new Folder();
|
||||
KnownFolders._temp[pathProperty] = path;
|
||||
KnownFolders._temp[isKnownProperty] = true;
|
||||
_temp = new Folder();
|
||||
_temp[pathProperty] = path;
|
||||
_temp[isKnownProperty] = true;
|
||||
}
|
||||
|
||||
return KnownFolders._temp;
|
||||
return _temp;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,8 @@ export class FileSystemAccess {
|
||||
private getFileExtension(path: string): string {
|
||||
var dotIndex = path.lastIndexOf(".");
|
||||
if (dotIndex && dotIndex >= 0 && dotIndex < path.length) {
|
||||
return path.substring(dotIndex);
|
||||
// return the extension without the "." (like in iOS)
|
||||
return path.substring(dotIndex + 1);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
Reference in New Issue
Block a user