mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Refactor the file-system-access API to be synchronous. Added *Sync equivalents of the file-system APIs. Removed usage of file-system-access within the code.
This commit is contained in:
200
file-system/file-system.d.ts
vendored
200
file-system/file-system.d.ts
vendored
@@ -7,134 +7,172 @@ declare module "file-system" {
|
||||
* Represents a single entity on the file system.
|
||||
*/
|
||||
export class FileSystemEntity {
|
||||
/**
|
||||
* Gets the Date object specifying the last time this entity was modified.
|
||||
*/
|
||||
/**
|
||||
* Gets the Date object specifying the last time this entity was modified.
|
||||
*/
|
||||
lastModified: Date;
|
||||
|
||||
/**
|
||||
* Gets the name of the entity.
|
||||
*/
|
||||
/**
|
||||
* Gets the name of the entity.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Gets the fully-qualified path (including the extension for a File) of the entity.
|
||||
*/
|
||||
/**
|
||||
* Gets the fully-qualified path (including the extension for a File) of the entity.
|
||||
*/
|
||||
path: string;
|
||||
|
||||
/**
|
||||
* Gets the Folder object representing the parent of this entity.
|
||||
* Will be null for a root folder like Documents or Temporary.
|
||||
* This property is readonly.
|
||||
*/
|
||||
/**
|
||||
* Gets the Folder object representing the parent of this entity.
|
||||
* Will be null for a root folder like Documents or Temporary.
|
||||
* This property is readonly.
|
||||
*/
|
||||
parent: Folder;
|
||||
|
||||
/**
|
||||
* Removes (deletes) the current Entity from the file system.
|
||||
*/
|
||||
/**
|
||||
* Removes (deletes) the current Entity from the file system.
|
||||
*/
|
||||
remove(): Promise<any>;
|
||||
|
||||
/**
|
||||
* Renames the current entity using the specified name.
|
||||
* @param newName The new name to be applied to the entity.
|
||||
*/
|
||||
/**
|
||||
* Removes (deletes) the current Entity from the file system synchronously.
|
||||
*/
|
||||
removeSync(onError?: (error: any) => any): void;
|
||||
|
||||
/**
|
||||
* Renames the current entity using the specified name.
|
||||
* @param newName The new name to be applied to the entity.
|
||||
*/
|
||||
rename(newName: string): Promise<any>;
|
||||
|
||||
/**
|
||||
* Renames the current entity synchronously, using the specified name.
|
||||
* @param newName The new name to be applied to the entity.
|
||||
*/
|
||||
renameSync(newName: string, onError?: (error: any) => any): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a File entity on the file system.
|
||||
*/
|
||||
export class File extends FileSystemEntity {
|
||||
/**
|
||||
* Checks whether a File with the specified path already exists.
|
||||
* @param path The path to check for.
|
||||
*/
|
||||
/**
|
||||
* Checks whether a File with the specified path already exists.
|
||||
* @param path The path to check for.
|
||||
*/
|
||||
static exists(path: string): boolean;
|
||||
|
||||
/**
|
||||
* Gets the extension of the file.
|
||||
*/
|
||||
/**
|
||||
* Gets the extension of the file.
|
||||
*/
|
||||
extension: string;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
isLocked: boolean;
|
||||
|
||||
/**
|
||||
* Gets or creates a File entity at the specified path.
|
||||
* @param path The path to get/create the file at.
|
||||
*/
|
||||
/**
|
||||
* Gets or creates a File entity at the specified path.
|
||||
* @param path The path to get/create the file at.
|
||||
*/
|
||||
static fromPath(path: string): File;
|
||||
|
||||
/**
|
||||
* Reads the content of the file as a string using the specified encoding (defaults to UTF-8).
|
||||
* @param encoding An optional value specifying the preferred encoding (defaults to UTF-8).
|
||||
*/
|
||||
/**
|
||||
* Reads the content of the file as a string using the specified encoding (defaults to UTF-8).
|
||||
* @param encoding An optional value specifying the preferred encoding (defaults to UTF-8).
|
||||
*/
|
||||
readText(encoding?: string): Promise<string>;
|
||||
|
||||
/**
|
||||
* Writes the provided string to the file, using the specified encoding (defaults to UTF-8).
|
||||
* @param content The content to be saved to the file.
|
||||
* @param encoding An optional value specifying the preferred encoding (defaults to UTF-8).
|
||||
*/
|
||||
/**
|
||||
* Reads the content of the file as a string synchronously, using the specified encoding (defaults to UTF-8).
|
||||
* @param onError An optional function to be called if some IO-error occurs.
|
||||
* @param encoding An optional value specifying the preferred encoding (defaults to UTF-8).
|
||||
*/
|
||||
readTextSync(onError?: (error: any) => any, encoding?: string): string;
|
||||
|
||||
/**
|
||||
* Writes the provided string to the file, using the specified encoding (defaults to UTF-8).
|
||||
* @param content The content to be saved to the file.
|
||||
* @param encoding An optional value specifying the preferred encoding (defaults to UTF-8).
|
||||
*/
|
||||
writeText(content: string, encoding?: string): Promise<any>;
|
||||
|
||||
/**
|
||||
* Writes the provided string to the file synchronously, using the specified encoding (defaults to UTF-8).
|
||||
* @param content The content to be saved to the file.
|
||||
* @param onError An optional function to be called if some IO-error occurs.
|
||||
* @param encoding An optional value specifying the preferred encoding (defaults to UTF-8).
|
||||
*/
|
||||
writeTextSync(content: string, onError?: (error: any) => any, encoding?: string): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a Folder (directory) entity on the file system.
|
||||
*/
|
||||
/**
|
||||
* Represents a Folder (directory) entity on the file system.
|
||||
*/
|
||||
export class Folder extends FileSystemEntity {
|
||||
/**
|
||||
* Determines whether this instance is a KnownFolder (accessed through the KnownFolders object).
|
||||
*/
|
||||
/**
|
||||
* Determines whether this instance is a KnownFolder (accessed through the KnownFolders object).
|
||||
*/
|
||||
isKnown: boolean;
|
||||
|
||||
/**
|
||||
* Gets or creates a Folder entity at the specified path.
|
||||
* @param path The path to get/create the folder at.
|
||||
*/
|
||||
/**
|
||||
* Gets or creates a Folder entity at the specified path.
|
||||
* @param path The path to get/create the folder at.
|
||||
*/
|
||||
static fromPath(path: string): Folder;
|
||||
|
||||
/**
|
||||
* Checks whether a Folder with the specified path already exists.
|
||||
* @param path The path to check for.
|
||||
*/
|
||||
/**
|
||||
* Checks whether a Folder with the specified path already exists.
|
||||
* @param path The path to check for.
|
||||
*/
|
||||
static exists(path: string): boolean;
|
||||
|
||||
/**
|
||||
* Checks whether this Folder contains an Entity with the specified name.
|
||||
* The path of the folder is added to the name to resolve the complete path to check for.
|
||||
* @param name The name of the entity to check for.
|
||||
*/
|
||||
/**
|
||||
* Checks whether this Folder contains an Entity with the specified name.
|
||||
* The path of the folder is added to the name to resolve the complete path to check for.
|
||||
* @param name The name of the entity to check for.
|
||||
*/
|
||||
contains(name: string): boolean;
|
||||
|
||||
/**
|
||||
* Deletes all the files and folders (recursively), contained within this Folder.
|
||||
*/
|
||||
/**
|
||||
* Deletes all the files and folders (recursively), contained within this Folder.
|
||||
*/
|
||||
clear(): Promise<any>;
|
||||
|
||||
/**
|
||||
* Gets or creates a File entity with the specified name within this Folder.
|
||||
* @param name The name of the file to get/create.
|
||||
*/
|
||||
/**
|
||||
* Deletes all the files and folders (recursively), contained within this Folder synchronously.
|
||||
* @param onError An optional function to be called if some error occurs.
|
||||
*/
|
||||
clearSync(onError?: (error: any) => void): void;
|
||||
|
||||
/**
|
||||
* Gets or creates a File entity with the specified name within this Folder.
|
||||
* @param name The name of the file to get/create.
|
||||
*/
|
||||
getFile(name: string): File;
|
||||
|
||||
/**
|
||||
* Gets or creates a Folder entity with the specified name within this Folder.
|
||||
* @param name The name of the folder to get/create.
|
||||
*/
|
||||
/**
|
||||
* Gets or creates a Folder entity with the specified name within this Folder.
|
||||
* @param name The name of the folder to get/create.
|
||||
*/
|
||||
getFolder(name: string): Folder;
|
||||
|
||||
/**
|
||||
* Gets all the top-level entities residing within this folder.
|
||||
*/
|
||||
/**
|
||||
* Gets all the top-level entities residing within this folder.
|
||||
*/
|
||||
getEntities(): Promise<Array<FileSystemEntity>>;
|
||||
|
||||
/**
|
||||
* Enumerates all the top-level FileSystem entities residing within this folder.
|
||||
* @param onEntity A callback that receives the current entity. If the callback returns false this will mean for the iteration to stop.
|
||||
*/
|
||||
/**
|
||||
* Gets all the top-level entities residing within this folder synchronously.
|
||||
* @param onError An optional function to be called if some error occurs.
|
||||
*/
|
||||
getEntitiesSync(onError?: (error: any) => any): Promise<Array<FileSystemEntity>>;
|
||||
|
||||
/**
|
||||
* Enumerates all the top-level FileSystem entities residing within this folder.
|
||||
* @param onEntity A callback that receives the current entity. If the callback returns false this will mean for the iteration to stop.
|
||||
*/
|
||||
eachEntity(onEntity: (entity: FileSystemEntity) => boolean);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user