chore: cleanup

This commit is contained in:
Nathan Walker
2020-07-06 14:25:11 -07:00
parent 94cf5c4706
commit 6336eac4b5
477 changed files with 59087 additions and 74961 deletions

View File

@@ -1,117 +1,96 @@
import { FileNameResolver as FileNameResolverDefinition } from ".";
import { PlatformContext } from "../../module-name-resolver/qualifier-matcher";
import { screen, device } from "../../platform";
import { path as fsPath, Folder, File } from "..";
import { Trace } from "../../trace";
import * as appCommonModule from "../../application/application-common";
import { FileNameResolver as FileNameResolverDefinition } from '.';
import { PlatformContext } from '../../module-name-resolver/qualifier-matcher';
import { screen, device } from '../../platform';
import { path as fsPath, Folder, File } from '..';
import { Trace } from '../../trace';
import * as appCommonModule from '../../application/application-common';
import {
findMatch,
stripQualifiers,
} from "../../module-name-resolver/qualifier-matcher";
import { findMatch, stripQualifiers } from '../../module-name-resolver/qualifier-matcher';
export class FileNameResolver implements FileNameResolverDefinition {
private _context: PlatformContext;
private _cache = {};
private _context: PlatformContext;
private _cache = {};
constructor(context: PlatformContext) {
console.log(
"FileNameResolver is deprecated; use ModuleNameResolver instead"
);
constructor(context: PlatformContext) {
console.log('FileNameResolver is deprecated; use ModuleNameResolver instead');
this._context = context;
}
this._context = context;
}
public resolveFileName(path: string, ext: string): string {
const key = path + ext;
let result: string = this._cache[key];
if (result === undefined) {
result = this.resolveFileNameImpl(path, ext);
this._cache[key] = result;
}
public resolveFileName(path: string, ext: string): string {
const key = path + ext;
let result: string = this._cache[key];
if (result === undefined) {
result = this.resolveFileNameImpl(path, ext);
this._cache[key] = result;
}
return result;
}
return result;
}
public clearCache(): void {
this._cache = {};
}
public clearCache(): void {
this._cache = {};
}
private resolveFileNameImpl(path: string, ext: string): string {
let result: string = null;
path = fsPath.normalize(path);
ext = "." + ext;
private resolveFileNameImpl(path: string, ext: string): string {
let result: string = null;
path = fsPath.normalize(path);
ext = '.' + ext;
// This call will return a clean path without qualifiers
path = stripQualifiers(path);
// This call will return a clean path without qualifiers
path = stripQualifiers(path);
const candidates = this.getFileCandidatesFromFolder(path, ext);
result = findMatch(path, ext, candidates, this._context);
const candidates = this.getFileCandidatesFromFolder(path, ext);
result = findMatch(path, ext, candidates, this._context);
return result;
}
return result;
}
private getFileCandidatesFromFolder(
path: string,
ext: string
): Array<string> {
const candidates = new Array<string>();
const folderPath = path.substring(
0,
path.lastIndexOf(fsPath.separator) + 1
);
private getFileCandidatesFromFolder(path: string, ext: string): Array<string> {
const candidates = new Array<string>();
const folderPath = path.substring(0, path.lastIndexOf(fsPath.separator) + 1);
if (Folder.exists(folderPath)) {
const folder = Folder.fromPath(folderPath);
folder.eachEntity((e) => {
if (e instanceof File) {
const file = e;
if (
file.path.indexOf(path) === 0 &&
file.extension === ext
) {
candidates.push(file.path);
}
}
if (Folder.exists(folderPath)) {
const folder = Folder.fromPath(folderPath);
folder.eachEntity((e) => {
if (e instanceof File) {
const file = e;
if (file.path.indexOf(path) === 0 && file.extension === ext) {
candidates.push(file.path);
}
}
return true;
});
} else {
if (Trace.isEnabled()) {
Trace.write(
"Could not find folder " +
folderPath +
" when loading " +
path +
ext,
Trace.categories.Navigation
);
}
}
return true;
});
} else {
if (Trace.isEnabled()) {
Trace.write('Could not find folder ' + folderPath + ' when loading ' + path + ext, Trace.categories.Navigation);
}
}
return candidates;
}
return candidates;
}
}
let resolverInstance: FileNameResolver;
export function resolveFileName(path: string, ext: string): string {
if (!resolverInstance) {
resolverInstance = new FileNameResolver({
width: screen.mainScreen.widthDIPs,
height: screen.mainScreen.heightDIPs,
os: device.os,
deviceType: device.deviceType,
});
}
if (!resolverInstance) {
resolverInstance = new FileNameResolver({
width: screen.mainScreen.widthDIPs,
height: screen.mainScreen.heightDIPs,
os: device.os,
deviceType: device.deviceType,
});
}
return resolverInstance.resolveFileName(path, ext);
return resolverInstance.resolveFileName(path, ext);
}
export function clearCache() {
if (resolverInstance) {
resolverInstance.clearCache();
}
if (resolverInstance) {
resolverInstance.clearCache();
}
}
appCommonModule.on("cssChanged", (args) => (resolverInstance = undefined));
appCommonModule.on("livesync", (args) => clearCache());
appCommonModule.on('cssChanged', (args) => (resolverInstance = undefined));
appCommonModule.on('livesync', (args) => clearCache());

View File

File diff suppressed because it is too large Load Diff

View File

@@ -2,291 +2,249 @@
* An utility class used to provide methods to access and work with the file system.
*/
export class FileSystemAccess {
/**
* Gets the last modified date of a file with a given path.
* @param path Path to the file.
*/
getLastModified(path: string): Date;
/**
* Gets the last modified date of a file with a given path.
* @param path Path to the file.
*/
getLastModified(path: string): Date;
/**
* Gets the size in bytes of a file with a given path.
* @param path Path to the file.
*/
getFileSize(path: string): number;
/**
* Gets the size in bytes of a file with a given path.
* @param path Path to the file.
*/
getFileSize(path: string): number;
/**
* Gets the parent folder of a file with a given path.
* @param path Path to the file.
* @param onError A callback function to use if any error occurs.
* Returns path Absolute path of the parent folder, name Name of the parent folder.
*/
getParent(
path: string,
onError?: (error: any) => any
): { path: string; name: string };
/**
* Gets the parent folder of a file with a given path.
* @param path Path to the file.
* @param onError A callback function to use if any error occurs.
* Returns path Absolute path of the parent folder, name Name of the parent folder.
*/
getParent(path: string, onError?: (error: any) => any): { path: string; name: string };
/**
* Gets a file from a given path.
* @param path Path to the file.
* @param onError A callback function to use if any error occurs.
* Returns path Absolute path of the file, name Name of the file, extension Extension of the file.
*/
getFile(
path: string,
onError?: (error: any) => any
): { path: string; name: string; extension: string };
/**
* Gets a file from a given path.
* @param path Path to the file.
* @param onError A callback function to use if any error occurs.
* Returns path Absolute path of the file, name Name of the file, extension Extension of the file.
*/
getFile(path: string, onError?: (error: any) => any): { path: string; name: string; extension: string };
/**
* Gets the folder of a file with a given path.
* @param path Path to the file.
* @param onError A callback function to use if any error occurs.
* Returns path Absolute path of the folder, name Name of the folder.
*/
getFolder(
path: string,
onError?: (error: any) => any
): { path: string; name: string };
/**
* Gets the folder of a file with a given path.
* @param path Path to the file.
* @param onError A callback function to use if any error occurs.
* Returns path Absolute path of the folder, name Name of the folder.
*/
getFolder(path: string, onError?: (error: any) => any): { path: string; name: string };
/**
* Gets all entities of a given path (folder)
* @param path Path to the file.
* @param onError (optional) A callback function to use if any error occurs.
* Returns an array of entities in the folder.
*/
getEntities(
path: string,
onError?: (error: any) => any
): Array<{ path: string; name: string; extension: string }>;
/**
* Gets all entities of a given path (folder)
* @param path Path to the file.
* @param onError (optional) A callback function to use if any error occurs.
* Returns an array of entities in the folder.
*/
getEntities(path: string, onError?: (error: any) => any): Array<{ path: string; name: string; extension: string }>;
/**
* Performs an action onSuccess for every entity in a folder with a given path.
* Breaks the loop if onSuccess function returns false
* @param path Path to the file.
* @param onEntity A callback function which is called for each entity.
* @param onError (optional) A callback function to use if any error occurs.
*/
eachEntity(
path: string,
onEntity: (entity: {
path: string;
name: string;
extension: string;
}) => boolean,
onError?: (error: any) => any
);
/**
* Performs an action onSuccess for every entity in a folder with a given path.
* Breaks the loop if onSuccess function returns false
* @param path Path to the file.
* @param onEntity A callback function which is called for each entity.
* @param onError (optional) A callback function to use if any error occurs.
*/
eachEntity(path: string, onEntity: (entity: { path: string; name: string; extension: string }) => boolean, onError?: (error: any) => any);
/**
* Checks if a file with a given path exist.
*/
fileExists(path: string): boolean;
/**
* Checks if a file with a given path exist.
*/
fileExists(path: string): boolean;
/**
* Checks if a folder with a given path exist.
*/
folderExists(path: string): boolean;
/**
* Checks if a folder with a given path exist.
*/
folderExists(path: string): boolean;
/**
* Deletes a file with a given path.
* @param path Path of the file.
* @param onError (optional) A callback function to use if any error occurs.
*/
deleteFile(path: string, onError?: (error: any) => any);
/**
* Deletes a file with a given path.
* @param path Path of the file.
* @param onError (optional) A callback function to use if any error occurs.
*/
deleteFile(path: string, onError?: (error: any) => any);
/**
* Deletes a folder with a given path.
* @param path Path of the folder.
* @param onError (optional) A callback function to use if any error occurs.
*/
deleteFolder(path: string, onError?: (error: any) => any);
/**
* Deletes a folder with a given path.
* @param path Path of the folder.
* @param onError (optional) A callback function to use if any error occurs.
*/
deleteFolder(path: string, onError?: (error: any) => any);
/**
* Deletes all content of a folder with a given path.
* @param path Path of the folder.
* @param onError (optional) A callback function to use if any error occurs.
*/
emptyFolder(path: string, onError?: (error: any) => any): void;
/**
* Deletes all content of a folder with a given path.
* @param path Path of the folder.
* @param onError (optional) A callback function to use if any error occurs.
*/
emptyFolder(path: string, onError?: (error: any) => any): void;
/**
* Rename a file or a folder with a given path.
* @param path Current path of the entity which should be renamed.
* @param newPath The new path which will be asigned of the entity.
* @param onError (optional) A callback function to use if any error occurs.
*/
rename(path: string, newPath: string, onError?: (error: any) => any): void;
/**
* Rename a file or a folder with a given path.
* @param path Current path of the entity which should be renamed.
* @param newPath The new path which will be asigned of the entity.
* @param onError (optional) A callback function to use if any error occurs.
*/
rename(path: string, newPath: string, onError?: (error: any) => any): void;
/**
* Gets the special documents folder.
* Returns for Android: "/data/data/applicationPackageName/files", iOS: "/var/mobile/Applications/appID/Documents"
*/
getDocumentsFolderPath(): string;
/**
* Gets the special documents folder.
* Returns for Android: "/data/data/applicationPackageName/files", iOS: "/var/mobile/Applications/appID/Documents"
*/
getDocumentsFolderPath(): string;
/**
* Gets the special temp folder.
* Returns for Android: "/data/data/applicationPackageName/cache", iOS: "/var/mobile/Applications/appID/Library/Caches"
*/
getTempFolderPath(): string;
/**
* Gets the special temp folder.
* Returns for Android: "/data/data/applicationPackageName/cache", iOS: "/var/mobile/Applications/appID/Library/Caches"
*/
getTempFolderPath(): string;
/**
* Gets the path to the logical root of the application - that is /path/to/appfiles/app.
*/
getLogicalRootPath(): string;
/**
* Gets the path to the logical root of the application - that is /path/to/appfiles/app.
*/
getLogicalRootPath(): string;
/**
* Gets the root folder for the current application. This Folder is private for the application and not accessible from Users/External apps.
* iOS - this folder is read-only and contains the app and all its resources.
*/
getCurrentAppPath(): string;
/**
* Gets the root folder for the current application. This Folder is private for the application and not accessible from Users/External apps.
* iOS - this folder is read-only and contains the app and all its resources.
*/
getCurrentAppPath(): string;
/**
* Reads a text from a file with a given path.
* @param path The path to the source file.
* @param onError (optional) A callback function to use if any error occurs.
* @param encoding (optional) If set reads the text with the specified encoding (default UTF-8).
* Returns the text read.
*/
readText(
path: string,
onError?: (error: any) => any,
encoding?: any
): string;
/**
* Reads a text from a file with a given path.
* @param path The path to the source file.
* @param onError (optional) A callback function to use if any error occurs.
* @param encoding (optional) If set reads the text with the specified encoding (default UTF-8).
* Returns the text read.
*/
readText(path: string, onError?: (error: any) => any, encoding?: any): string;
/**
* Reads a text from a file with a given path.
* @param path The path to the source file.
* @param encoding (optional) If set reads the text with the specified encoding (default UTF-8).
* Returns Promise of the text read.
*/
readTextAsync(path: string, encoding?: any): Promise<string>;
/**
* Reads a text from a file with a given path.
* @param path The path to the source file.
* @param encoding (optional) If set reads the text with the specified encoding (default UTF-8).
* Returns Promise of the text read.
*/
readTextAsync(path: string, encoding?: any): Promise<string>;
/**
* Reads a text from a file with a given path.
* @param path The path to the source file.
* @param onError (optional) A callback function to use if any error occurs.
* @param encoding (optional) If set reads the text with the specified encoding (default UTF-8).
* Returns the text read.
*/
readTextSync(
path: string,
onError?: (error: any) => any,
encoding?: any
): string;
/**
* Reads a text from a file with a given path.
* @param path The path to the source file.
* @param onError (optional) A callback function to use if any error occurs.
* @param encoding (optional) If set reads the text with the specified encoding (default UTF-8).
* Returns the text read.
*/
readTextSync(path: string, onError?: (error: any) => any, encoding?: any): string;
/**
* Reads a binary content from a file with a given path.
* @param path The path to the source file.
* @param onError (optional) A callback function to use if any error occurs.
* Returns the binary content read.
*/
read(path: string, onError?: (error: any) => any): any;
/**
* Reads a binary content from a file with a given path.
* @param path The path to the source file.
* @param onError (optional) A callback function to use if any error occurs.
* Returns the binary content read.
*/
read(path: string, onError?: (error: any) => any): any;
/**
* Reads a binary content from a file with a given path.
* @param path The path to the source file.
* Returns a Promise with the binary content read.
*/
readAsync(path: string): Promise<any>;
/**
* Reads a binary content from a file with a given path.
* @param path The path to the source file.
* Returns a Promise with the binary content read.
*/
readAsync(path: string): Promise<any>;
/**
* Reads a binary content from a file with a given path.
* @param path The path to the source file.
* @param onError (optional) A callback function to use if any error occurs.
* Returns the binary content read.
*/
readSync(path: string, onError?: (error: any) => any): any;
/**
* Reads a binary content from a file with a given path.
* @param path The path to the source file.
* @param onError (optional) A callback function to use if any error occurs.
* Returns the binary content read.
*/
readSync(path: string, onError?: (error: any) => any): any;
/**
* Writes a text to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
* @param onError (optional) A callback function to use if any error occurs.
* @param encoding (optional) If set writes the text with the specified encoding (default UTF-8).
*/
writeText(
path: string,
content: string,
onError?: (error: any) => any,
encoding?: any
);
/**
* Writes a text to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
* @param onError (optional) A callback function to use if any error occurs.
* @param encoding (optional) If set writes the text with the specified encoding (default UTF-8).
*/
writeText(path: string, content: string, onError?: (error: any) => any, encoding?: any);
/**
* Writes a text to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
* @param encoding (optional) If set writes the text with the specified encoding (default UTF-8).
*/
writeTextAsync(
path: string,
content: string,
encoding?: any
): Promise<void>;
/**
* Writes a text to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
* @param encoding (optional) If set writes the text with the specified encoding (default UTF-8).
*/
writeTextAsync(path: string, content: string, encoding?: any): Promise<void>;
/**
* Writes a text to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
* @param onError (optional) A callback function to use if any error occurs.
* @param encoding (optional) If set writes the text with the specified encoding (default UTF-8).
*/
writeTextSync(
path: string,
content: string,
onError?: (error: any) => any,
encoding?: any
);
/**
* Writes a text to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
* @param onError (optional) A callback function to use if any error occurs.
* @param encoding (optional) If set writes the text with the specified encoding (default UTF-8).
*/
writeTextSync(path: string, content: string, onError?: (error: any) => any, encoding?: any);
/**
* Writes a binary to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
* @param onError (optional) A callback function to use if any error occurs.
*/
write(path: string, content: any, onError?: (error: any) => any);
/**
* Writes a binary to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
* @param onError (optional) A callback function to use if any error occurs.
*/
write(path: string, content: any, onError?: (error: any) => any);
/**
* Writes a binary to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
*/
writeAsync(path: string, content: any): Promise<void>;
/**
* Writes a binary to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
*/
writeAsync(path: string, content: any): Promise<void>;
/**
* Writes a binary to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
* @param onError (optional) A callback function to use if any error occurs.
*/
writeSync(path: string, content: any, onError?: (error: any) => any);
/**
* Writes a binary to a file with a given path.
* @param path The path to the source file.
* @param content The content which will be written to the file.
* @param onError (optional) A callback function to use if any error occurs.
*/
writeSync(path: string, content: any, onError?: (error: any) => any);
/**
* Gets extension of the file with a given path.
* @param path A path to the file.
*/
getFileExtension(path: string): string;
/**
* Gets extension of the file with a given path.
* @param path A path to the file.
*/
getFileExtension(path: string): string;
/**
* Gets the path separator (for the current platform).
*/
getPathSeparator(): string;
/**
* Gets the path separator (for the current platform).
*/
getPathSeparator(): string;
/**
* Normalizes a path.
* @param path A path which should be normalized.
* Returns a normalized path as string.
*/
normalizePath(path: string): string;
/**
* Normalizes a path.
* @param path A path which should be normalized.
* Returns a normalized path as string.
*/
normalizePath(path: string): string;
/**
* Joins two paths (without normalize). Only removes some trailing and duplicate path separators.
* @param left First path to join.
* @param right Second path to join.
* Returns the joined path.
*/
joinPath(left: string, right: string): string;
/**
* Joins two paths (without normalize). Only removes some trailing and duplicate path separators.
* @param left First path to join.
* @param right Second path to join.
* Returns the joined path.
*/
joinPath(left: string, right: string): string;
/**
* Joins an array of file paths.
* @param paths An array of paths.
* Returns the joined path.
*/
joinPaths(paths: string[]): string;
/**
* Joins an array of file paths.
* @param paths An array of paths.
* Returns the joined path.
*/
joinPaths(paths: string[]): string;
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -2,292 +2,288 @@
* Represents a single entity on the file system.
*/
export class FileSystemEntity {
/**
* Gets the Date object specifying the last time this entity was modified.
*/
lastModified: Date;
/**
* Gets the Date object specifying the last time this entity was modified.
*/
lastModified: Date;
/**
* Gets the name of the entity.
*/
name: string;
/**
* Gets the name of the entity.
*/
name: string;
/**
* Gets the fully-qualified path (including the extension for a File) of the entity.
*/
path: string;
/**
* 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.
*/
parent: Folder;
/**
* 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.
*/
remove(): Promise<any>;
/**
* Removes (deletes) the current Entity from the file system.
*/
remove(): Promise<any>;
/**
* Removes (deletes) the current Entity from the file system synchronously.
*/
removeSync(onError?: (error: any) => any): void;
/**
* 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 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;
/**
* 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.
*/
static exists(path: string): boolean;
/**
* 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.
*/
extension: string;
/**
* Gets the extension of the file.
*/
extension: string;
/**
* Gets the size in bytes of the file.
*/
size: number;
/**
* Gets the size in bytes of the file.
*/
size: number;
/**
* Gets a value indicating whether the file is currently locked, meaning a background operation associated with this file is running.
*/
isLocked: boolean;
/**
* 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.
*/
static fromPath(path: string): File;
/**
* 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).
*/
readText(encoding?: string): Promise<string>;
/**
* 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>;
/**
* 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;
/**
* 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;
/**
* Reads the binary content of the file asynchronously.
*/
read(): Promise<any>;
/**
* Reads the binary content of the file asynchronously.
*/
read(): Promise<any>;
/**
* Reads the binary content of the file synchronously.
* @param onError An optional function to be called if some IO-error occurs.
*/
readSync(onError?: (error: any) => any): any;
/**
* Reads the binary content of the file synchronously.
* @param onError An optional function to be called if some IO-error occurs.
*/
readSync(onError?: (error: any) => any): any;
/**
* 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, 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;
/**
* 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;
/**
* Writes the provided binary content to the file.
* @param content The binary content to be saved to the file.
*/
write(content: any): Promise<void>;
/**
* Writes the provided binary content to the file.
* @param content The binary content to be saved to the file.
*/
write(content: any): Promise<void>;
/**
* Writes the provided binary content to the file synchronously.
* @param content The binary content to be saved to the file.
* @param onError An optional function to be called if some IO-error occurs.
*/
writeSync(content: any, onError?: (error: any) => any): void;
/**
* Writes the provided binary content to the file synchronously.
* @param content The binary content to be saved to the file.
* @param onError An optional function to be called if some IO-error occurs.
*/
writeSync(content: any, onError?: (error: any) => any): void;
}
/**
* 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).
*/
isKnown: boolean;
/**
* 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.
*/
static fromPath(path: string): Folder;
/**
* 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.
*/
static exists(path: string): boolean;
/**
* 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.
*/
contains(name: 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.
*/
contains(name: string): boolean;
/**
* Deletes all the files and folders (recursively), contained within this Folder.
*/
clear(): Promise<any>;
/**
* Deletes all the files and folders (recursively), contained within this Folder.
*/
clear(): Promise<any>;
/**
* 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;
/**
* 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 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.
*/
getFolder(name: string): Folder;
/**
* 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.
*/
getEntities(): Promise<Array<FileSystemEntity>>;
/**
* Gets all the top-level entities residing within this folder.
*/
getEntities(): Promise<Array<FileSystemEntity>>;
/**
* 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): Array<FileSystemEntity>;
/**
* 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): 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);
/**
* 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);
}
/**
* Provides access to the top-level Folders instances that are accessible from the application. Use these as entry points to access the FileSystem.
*/
export 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.
*/
export function documents(): Folder;
/**
* Gets the Documents folder available for the current application. This Folder is private for the application and not accessible from Users/External apps.
*/
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.
*/
export function temp(): 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.
*/
export function temp(): Folder;
/**
* Gets the root folder for the current application. This Folder is private for the application and not accessible from Users/External apps.
* iOS - this folder is read-only and contains the app and all its resources.
*/
export function currentApp(): Folder;
/**
* Gets the root folder for the current application. This Folder is private for the application and not accessible from Users/External apps.
* iOS - this folder is read-only and contains the app and all its resources.
*/
export function currentApp(): Folder;
/**
* Contains iOS-specific known folders.
*/
module ios {
/**
* Gets the NSLibraryDirectory. Note that the folder will not be created if it did not exist.
*/
export function library(): Folder;
/**
* Contains iOS-specific known folders.
*/
module ios {
/**
* Gets the NSLibraryDirectory. Note that the folder will not be created if it did not exist.
*/
export function library(): Folder;
/**
* Gets the NSDeveloperDirectory. Note that the folder will not be created if it did not exist.
*/
export function developer(): Folder;
/**
* Gets the NSDeveloperDirectory. Note that the folder will not be created if it did not exist.
*/
export function developer(): Folder;
/**
* Gets the NSDesktopDirectory. Note that the folder will not be created if it did not exist.
*/
export function desktop(): Folder;
/**
* Gets the NSDesktopDirectory. Note that the folder will not be created if it did not exist.
*/
export function desktop(): Folder;
/**
* Gets the NSDownloadsDirectory. Note that the folder will not be created if it did not exist.
*/
export function downloads(): Folder;
/**
* Gets the NSDownloadsDirectory. Note that the folder will not be created if it did not exist.
*/
export function downloads(): Folder;
/**
* Gets the NSMoviesDirectory. Note that the folder will not be created if it did not exist.
*/
export function movies(): Folder;
/**
* Gets the NSMoviesDirectory. Note that the folder will not be created if it did not exist.
*/
export function movies(): Folder;
/**
* Gets the NSMusicDirectory. Note that the folder will not be created if it did not exist.
*/
export function music(): Folder;
/**
* Gets the NSMusicDirectory. Note that the folder will not be created if it did not exist.
*/
export function music(): Folder;
/**
* Gets the NSPicturesDirectory. Note that the folder will not be created if it did not exist.
*/
export function pictures(): Folder;
/**
* Gets the NSPicturesDirectory. Note that the folder will not be created if it did not exist.
*/
export function pictures(): Folder;
/**
* Gets the NSSharedPublicDirectory. Note that the folder will not be created if it did not exist.
*/
export function sharedPublic(): Folder;
}
/**
* Gets the NSSharedPublicDirectory. Note that the folder will not be created if it did not exist.
*/
export function sharedPublic(): Folder;
}
}
/**
* Enables path-specific operations like join, extension, etc.
*/
export module path {
/**
* Normalizes a path, taking care of occurrances like ".." and "//".
* @param path The path to be normalized.
*/
export function normalize(path: string): string;
/**
* Normalizes a path, taking care of occurrances like ".." and "//".
* @param path The path to be normalized.
*/
export function normalize(path: string): string;
/**
* Joins all the provided string components, forming a valid and normalized path.
* @param paths An array of string components to be joined.
*/
export function join(...paths: string[]): string;
/**
* Joins all the provided string components, forming a valid and normalized path.
* @param paths An array of string components to be joined.
*/
export function join(...paths: string[]): string;
/**
* Gets the string used to separate file paths.
*/
export const separator: string;
/**
* Gets the string used to separate file paths.
*/
export const separator: string;
}

View File

File diff suppressed because it is too large Load Diff