File I/O utilities.
import {
fileExists,
fileCleaner,
writeTextFile,
writeJsonFile,
fileWriter,
fileCopy,
readFile,
origFile,
fileObj,
handleFile,
jsonRead,
fileMove,
fileHandler,
isXHTML,
testWrite,
} from '@epubknowledge/common/file'| Export | Description |
|---|---|
fileExists(path) |
Returns true if the path exists and is a file |
fileCleaner(path | path[]) |
Removes one or more files and returns true; throws if an input exists but is not a file |
writeTextFile(path, data) |
Writes UTF-8 text to disk synchronously |
writeJsonFile(path, data) |
Writes a JSON object to disk synchronously |
fileWriter({ filePath, data, json }) |
Writes a string or JSON object to disk. data and json are optional; they default to "" and false |
fileCopy(src, dest) |
Copies a file; throws on failure |
readFile(path) |
Reads a file as UTF-8 text |
origFile(path) |
Returns a name_orig.ext filename for backup naming |
fileObj(path) |
Parses a file path into a FileObj descriptor |
handleFile(path) |
Parses a file path into a FileInfo descriptor (includes fullPath) |
jsonRead(name) |
Reads cwd()/json/<name>.json from the json/ subdirectory under the current working directory |
fileMove(src, dest) |
Moves a file asynchronously; throws on failure |
fileHandler({ file, dest, data }) |
Writes data to file, then moves it to dest |
isXHTML(path) |
Returns true if the path has a .xhtml extension and contains the XHTML namespace |
testWrite(data, ext?) |
Writes debug output to a timestamped file on the Desktop or OS tmp directory when the Desktop path is unavailable |