webcad-api/types/Common/FileSystem.d.ts
2020-09-24 11:04:12 +08:00

176 lines
5.4 KiB
TypeScript

/**
* FileSystem is used to read and write files using nunuStudio.
*
* Some operations are platform specific and might not work everywhere.
*/
export declare class FileSystem {
static fs: any;
/**
* Read file content as text.
*
* @method readFile
* @param {String} fname URL to the file.
* @param {boolean} sync If true the file will be read in sync.
* @param {Function} onLoad onLoad callback.
* @param {Function} onProgress onProgress callback.
* @return {String} File content as a string, null if reading async.
*/
static readFile: (fname: any, sync: any, onLoad: any, onProgress: any) => any;
/**
* Read file as arraybuffer data.
*
* @method readFileArrayBuffer
* @param {String} fname Name of the file
* @param {boolean} sync If true the file will be read in sync.
* @param {Function} onLoad onLoad callback.
* @param {Function} onProgress onProgress callback.
* @return {ArrayBuffer} File data as array buffer, null on error
*/
static readFileArrayBuffer: (fname: any, sync?: any, onLoad?: any, onProgress?: any) => ArrayBuffer;
/**
* Read file as base64 data.
*
* @method readFileBase64
* @param {String} fname Name of the file
* @param {boolean} sync If true the file will be read in sync.
* @param {Function} onLoad onLoad callback.
* @param {Function} onProgress onProgress callback.
* @return {String} File data in base64, null on error
*/
static readFileBase64: (fname: any, sync?: any, onLoad?: any, onProgress?: any) => string;
static ReadFileAsText(file: File): Promise<string>;
/**
* Write text file.
*
* When running without NWJS it writes file as a blob and auto downloads it.
*
* @method writeFile
* @param {String} fname File name.
* @param {String} data Text to be written to the file.
*/
static WriteFile(fname: string, data: BlobPart): void;
/**
* Write binary file using base64 data.
*
* @method writeFileBase64
* @param {String} fname
* @param {String} data
*/
static writeFileBase64: (fname: any, data: any) => void;
/**
* Write binary file using arraybuffer data.
*
* @method writeFileArrayBuffer
* @param {String} fname
* @param {String} data
*/
static writeFileArrayBuffer(fname: any, data: any): void;
static chooserInput: HTMLInputElement;
/**
*
*/
static ChooseFile({ filter, multiple, callback }: {
filter?: string;
multiple?: boolean;
callback: (filelist: FileList) => void;
}): void;
/**
* Used as an alternative to chooseFile for saving files in the browser.
*
* Uses a prompt to question the user the file name.
*
* @method chooseFileName
* @param {Function} onLoad onLoad callback
* @param {String} saveas File extension
*/
static chooseFileName: (onLoad: any, saveas: any, name: any) => void;
/**
* Copy file (cannot be used to copy folders).
*
* Only works when running inside NWJS.
*
* @method copyFile
* @param {String} src
* @param {String} dst
*/
static copyFile: (src: any, dst: any) => void;
/**
* Make a directory (dont trow exeption if directory already exists).
*
* Only works when running inside NWJS.
*
* @method makeDirectory
* @param {String} dir
*/
static makeDirectory: (dir: any) => void;
/**
* Returns files in directory (returns empty array in case of error).
*
* Only works when running inside NWJS.
*
* @method getFilesDirectory
* @return {Array} Files in the directory
*/
static getFilesDirectory: (dir: any) => any;
/**
* Copy folder and all its files (includes symbolic links).
*
* Only works when running inside NWJS.
*
* @method copyFolder
* @param {String} src
* @param {String} dst
*/
static copyFolder: (src: any, dst: any) => void;
/**
* Check if a file exists.
*
* Only works inside of NWJS. When running inside the browser always returns false.
*
* @method fileExists
* @param {String} file File path
* @return {boolean} True is file exists
*/
static fileExists: (file: any) => any;
/**
* Get file name without extension from file path string.
*
* If input is a/b/c/abc.d output is abc.
*
* @method getFileName
* @param {String} file File path
* @return {String} File name without path and extension
*/
static getFileName: (file: any) => any;
/**
* Get file name without extension.
*
* If input is a/b/c/abc.d output is a/b/c/abc.
*
* @method getNameWithoutExtension
* @param {String} file File path
* @return {String}
*/
static getNameWithoutExtension: (file: any) => any;
/**
* Get file directoty.
*
* If input is a/b/c/abc.d output is a/b/c/
*
* @method getFilePath
* @param {String} file File path
* @return {String}
*/
static getFilePath: (file: any) => any;
/**
* Get file extension from file path string (always in lowercase).
*
* If input is a/b/c/abc.d output is d.
*
* @method getFileExtension
* @param {String} file File path
* @return {String}
*/
static getFileExtension: (file: any) => any;
}
//# sourceMappingURL=FileSystem.d.ts.map