node-promfs v3.7.0
node-promfs
'fs' object extensions & promisifications
Installation
$ npm install node-promfsFeatures
promise all fs asynchronous functions
checks for file & directory existence, with synchrone & asynchrone versions
- extract directory's files, with synchrone & asynchrone versions
- create & delete directories recursively, with synchrone & asynchrone versions
- concat files content in a string or a file, with synchrone & asynchrone versions
- copy files, with synchrone & asynchrone versions
Doc
$ npx node-promfs mkdirp <file: string> <?mode: number>
$ npx node-promfs rmdirp <file: string>you can use following method by replacing uppercase by lowercase with "-" before (ex : directoryToFile => "directory-to-file") Array arguments "files-to-file", "files-to-string", etc... is just list of strings (ex : "1", "2" => "1" "2")
type tError = ReferenceError|TypeError|Error|null;
type tCallback = (err: tError, data: any) => void;interface iReadJSONOptions {
"encoding"?: string;
"flag"?: string;
"signal"?: AbortSignal;
}
interface iWriteJSONOptions extends iReadJSONOptions {
"mode"?: number;
"replacer"?: (k, v) => any;
"space"?: string|number|null;
}
type tReadJSONOptions = string|iReadJSONOptions|null;
type tWriteJSONOptions = string|iWriteJSONOptions|null;-- Extended --
in "separator" parameter, you can use "{{filename}}" pattern, it will be replaced by the file's basename (ex : separator = "\r\n\r\n--- {{filename}} ---\r\n\r\n")
isFile : does the file exists and is a regular file ?
isFile(file: string, callback: (err: tError, exists: boolean) => void): voidisFileSync(file: string): booleanisFileProm(file: string): Promise<boolean>isDirectory : does the file exists and is a directory ?
isDirectory(dir: string, callback: (err: tError, exists: boolean) => void): voidisDirectorySync(dir: string): booleanisDirectoryProm(dir: string): Promise<boolean>
copyFile : copy a file with streams (copy then control with isFile)
copyFile(origin: string, target: string, callback: (err: tError) => void): voidcopyFileSync(origin: string, target: string): voidcopyFileProm(origin: string, target: string): Promise<void>extractFiles : return only files from a directory
extractFiles(dir: string, callback: (err: tError, files: Array<string>) => void): voidextractFilesSync(dir: string): Array<string>extractFilesProm(dir: string): Promise<Array<string>>writeJSONFile : stringify JSON and writeFile
writeJSONFile(file: string, data: any, options: tCallback | tWriteJSONOptions, callback?: tCallback): voidwriteJSONFileSync(file: string, data: any, options?: tReadJSONOptions): voidwriteJSONFileProm(file: string, data: any, options?: tReadJSONOptions): Promise<void>readJSONFile : readFile and parse JSON
readJSONFile(file: string, opts: tCallback | tReadJSONOptions, callback?: tCallback): voidreadJSONFileSync(file: string, opts?: tReadJSONOptions): anyreadJSONFileProm(file: string, opts?: tReadJSONOptions) : Promise<any>
mkdirp : recursively create a directory
- The arguments are the same as the official documentation's ones for mkdir & mkdirSync
mkdirp(path: string, callback: (err: tError, data: any) => void): voidmkdirp(path: string, mode: number, callback: (err: tError, data: any) => void): voidmkdirpSync(path: string, mode?: number): voidmkdirpProm(path: string, mode?: number): Promise<void>rmdirp : recursively delete a directory
rmdirp(path: string, callback: (err: tError) => void): voidrmdirpSync(path: string): voidrmdirpProm(path: string): Promise<void>
filesToStream : converge files content in a Readable stream
filesToStream(files: Array<string>, callback: (err: tError, Transform) => void): voidfilesToStream(files: Array<string>, separator: string, callback: (err: tError, data: Transform) => void): voidfilesToStreamSync(path: string, separator?: string): TransformfilesToStreamProm(path: string, separator?: string): Promise<Transform>filesToString : concat files content in a string
filesToString(files: Array<string>, callback: (err: tError, data: string) => void): voidfilesToString(files: Array<string>, separator: string, callback: (err: tError, data: string) => void): voidfilesToStringSync(files: Array<string>, separator?: string): stringfilesToStringProm(files: Array<string>, separator?: string): Promise<string>filesToFile : concat files content in a file with streams
filesToFile(files: Array<string>, file: string, callback: (err: tError) => void): voidfilesToFile(files: Array<string>, file: string, separator: string, callback: (err: tError) => void): voidfilesToFileSync(files: Array<string>, file: string, separator?: string): voidfilesToFileProm(files: Array<string>, file: string, separator?: string): Promise<void>
directoryToStream : converge directory's files content in a Readable stream
directoryToStream(directory: string, file: string, callback: (err: tError, data: Transform) => void): voiddirectoryToStream(directory: string, separator: string, callback: (err: tError, data: Transform) => void): voiddirectoryToStreamSync(directory: string, file: string, separator?: string): TransformdirectoryToStreamProm(directory: string, file: string, separator?: string): Promise<Transform>directoryToString : concat directory's files content in a string
directoryToString(directory: string, callback: (err: tError, data: Transform) => void): voiddirectoryToString(directory: string, separator: string, callback: (err: tError, data: Transform) => void): voiddirectoryToStringSync(directory: string, separator?: string): TransformdirectoryToStringProm(directory: string, separator?: string): Promise<Transform>directoryToFile : concat directory's files content in a file
directoryToFile(directory: string, file: string, callback: (err: tError) => void): voiddirectoryToFile(directory: string, file: string, separator: string, callback: (err: tError) => void)directoryToFileSync(directory: string, file: string, separator?: string): voiddirectoryToFileProm(directory: string, file: string, separator?: string): Promise<void>
-- Classical --
- The arguments are the same as the official documentation's ones
- "then" data are the same as the callbacks' ones
- all the methods cannot be tested (too much arguments)
accessProm(): Promise-> testedappendFileProm(): Promise-> testedchmodProm(): Promise-> testedchownProm(): Promise-> testedcloseProm(): Promise-> testedfchmodProm(): PromisefchownProm(): PromisefdatasyncProm(): PromisefstatProm(): PromisefsyncProm(): PromiseftruncateProm(): PromisefutimesProm(): PromiselinkProm(): PromiselstatProm(): PromisemkdirProm(): Promise-> testedmkdtempProm(): PromiseopenProm(): Promise-> testedreaddirProm(): Promise-> testedreadFileProm(): Promise-> testedrealpathProm(): Promise-> testedrenameProm(): Promise-> testedrmdirProm(): Promise-> testedstatProm(): PromisetruncateProm(): PromiseunlinkProm(): Promise-> testedutimesProm(): PromisewriteProm(): PromisewriteFileProm(): Promise-> tested
Import
Native
const fs = require("node-promfs");
const { readJSONFileProm } = require("node-promfs");Typescript
import fs = require("node-promfs");Tests
$ git clone git://github.com/Psychopoulet/node-promfs.git
$ cd ./node-promfs
$ npm install
$ npm run-script testsLicense
5 years ago
5 years ago
5 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago