mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 12:57:42 +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.
|
* 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.
|
* 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.
|
* 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 createFolder = function (info: { path: string; name: string; }) {
|
||||||
var documents = KnownFolders.documents();
|
var documents = knownFolders.documents();
|
||||||
if (info.path === documents.path) {
|
if (info.path === documents.path) {
|
||||||
return documents;
|
return documents;
|
||||||
}
|
}
|
||||||
|
|
||||||
var temp = KnownFolders.temporary();
|
var temp = knownFolders.temp();
|
||||||
if (info.path === temp.path) {
|
if (info.path === temp.path) {
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
@ -48,8 +48,8 @@ var createFolder = function (info: { path: string; name: string; }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the basic file system entity - a File or a Folder.
|
* Represents the basic file system entity - a File or a Folder.
|
||||||
*/
|
*/
|
||||||
export class FileSystemEntity {
|
export class FileSystemEntity {
|
||||||
/**
|
/**
|
||||||
* Gets the Folder object representing the parent of this entity. Will be null for a root folder like Documents or Temporary.
|
* Gets the Folder object representing the parent of this entity. Will be null for a root folder like Documents or Temporary.
|
||||||
@ -160,6 +160,7 @@ export class File extends FileSystemEntity {
|
|||||||
|
|
||||||
return createFile(fileInfo);
|
return createFile(fileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a File with the specified path already exists.
|
* Checks whether a File with the specified path already exists.
|
||||||
*/
|
*/
|
||||||
@ -174,6 +175,7 @@ export class File extends FileSystemEntity {
|
|||||||
this.checkAccess();
|
this.checkAccess();
|
||||||
return new FileReader(this);
|
return new FileReader(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a FileWriter object over this file and locks the file until the writer is released.
|
* 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();
|
this.checkAccess();
|
||||||
return new FileWriter(this);
|
return new FileWriter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the extension of the entity.
|
* Gets the extension of the entity.
|
||||||
*/
|
*/
|
||||||
get extension(): string {
|
get extension(): string {
|
||||||
return this[extensionProperty];
|
return this[extensionProperty];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a value indicating whether the file is currently locked, meaning a background operation associated with this file is running.
|
* Gets a value indicating whether the file is currently locked, meaning a background operation associated with this file is running.
|
||||||
*/
|
*/
|
||||||
@ -204,8 +208,8 @@ export class File extends FileSystemEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Folder entity.
|
* Represents a Folder entity.
|
||||||
*/
|
*/
|
||||||
export class Folder extends FileSystemEntity {
|
export class Folder extends FileSystemEntity {
|
||||||
/**
|
/**
|
||||||
* Attempts to access a Folder at the specified path and creates a new Folder if there is no existing one.
|
* Attempts to access a Folder at the specified path and creates a new Folder if there is no existing one.
|
||||||
@ -315,44 +319,44 @@ 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.
|
* 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 {
|
export module knownFolders {
|
||||||
private static _documents: Folder;
|
var _documents: Folder;
|
||||||
private static _temp: 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.
|
* 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 var documents = function (): Folder {
|
||||||
if (!KnownFolders._documents) {
|
if (!_documents) {
|
||||||
var path = getFileAccess().getDocumentsFolderPath();
|
var path = getFileAccess().getDocumentsFolderPath();
|
||||||
KnownFolders._documents = new Folder();
|
_documents = new Folder();
|
||||||
KnownFolders._documents[pathProperty] = path;
|
_documents[pathProperty] = path;
|
||||||
KnownFolders._documents[isKnownProperty] = true;
|
_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.
|
* 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 var temp = function (): Folder {
|
||||||
if (!KnownFolders._temp) {
|
if (!_temp) {
|
||||||
var path = getFileAccess().getTempFolderPath();
|
var path = getFileAccess().getTempFolderPath();
|
||||||
KnownFolders._temp = new Folder();
|
_temp = new Folder();
|
||||||
KnownFolders._temp[pathProperty] = path;
|
_temp[pathProperty] = path;
|
||||||
KnownFolders._temp[isKnownProperty] = true;
|
_temp[isKnownProperty] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return KnownFolders._temp;
|
return _temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for FileReader and FileWriter APIs.
|
* Base class for FileReader and FileWriter APIs.
|
||||||
*/
|
*/
|
||||||
export class FileAccess {
|
export class FileAccess {
|
||||||
private _file;
|
private _file;
|
||||||
|
|
||||||
@ -378,8 +382,8 @@ export class FileAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables reading the content of a File entity.
|
* Enables reading the content of a File entity.
|
||||||
*/
|
*/
|
||||||
export class FileReader extends FileAccess {
|
export class FileReader extends FileAccess {
|
||||||
/**
|
/**
|
||||||
* Reads the content of the underlying File as a UTF8 encoded string.
|
* Reads the content of the underlying File as a UTF8 encoded string.
|
||||||
@ -390,8 +394,8 @@ export class FileReader extends FileAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables saving data to a File entity.
|
* Enables saving data to a File entity.
|
||||||
*/
|
*/
|
||||||
export class FileWriter extends FileAccess {
|
export class FileWriter extends FileAccess {
|
||||||
public writeText(content: string, onSuccess?: () => any, onError?: (error: any) => any) {
|
public writeText(content: string, onSuccess?: () => any, onError?: (error: any) => any) {
|
||||||
getFileAccess().writeText(this.file.path, content, onSuccess, onError);
|
getFileAccess().writeText(this.file.path, content, onSuccess, onError);
|
||||||
|
@ -349,7 +349,8 @@ export class FileSystemAccess {
|
|||||||
private getFileExtension(path: string): string {
|
private getFileExtension(path: string): string {
|
||||||
var dotIndex = path.lastIndexOf(".");
|
var dotIndex = path.lastIndexOf(".");
|
||||||
if (dotIndex && dotIndex >= 0 && dotIndex < path.length) {
|
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;
|
return undefined;
|
||||||
|
Reference in New Issue
Block a user