Comparing version 3.1.9 to 3.2.3
71
index.js
@@ -6,2 +6,3 @@ 'use strict'; | ||
var Debug = require('debug'); | ||
var readline = require('readline'); | ||
@@ -293,21 +294,22 @@ function _interopNamespaceDefault(e) { | ||
/** | ||
* readFile | ||
* writeFile | ||
* @param {*} filePath | ||
* @param {*} options https://nodejs.org/dist/latest-v16.x/docs/api/fs.html#fsreadfilesyncpath-options | ||
* @returns | ||
* @param {*} fileData | ||
* @param {*} options https://nodejs.org/dist/latest-v16.x/docs/api/fs.html#fswritefilesyncfile-data-options | ||
*/ | ||
const readFile = async (filePath, options) => { | ||
const writeFile = async (filePath, fileData, options) => { | ||
// check | ||
debug$1('/ readFile / filePath', filePath); | ||
debug$1('/ writeFile / filePath', filePath); | ||
if (!filePath) return; | ||
try { | ||
// opt | ||
const opt = { encoding: 'utf8' }; | ||
options = options || opt; | ||
debug$1('/ readFile / options', options); | ||
// vars | ||
fileData = fileData || ''; | ||
options = options || {}; | ||
debug$1('/ writeFile / options', options); | ||
return await fsExtra.readFile(filePath, options); | ||
await fsExtra.outputFile(filePath, fileData, options); | ||
return true; | ||
} catch (e) { | ||
debug$1('/ readFile / fail'); | ||
debug$1('/ writeFile / fail'); | ||
console.log(e); | ||
@@ -321,22 +323,21 @@ } | ||
/** | ||
* writeFile | ||
* readFile | ||
* @param {*} filePath | ||
* @param {*} fileData | ||
* @param {*} options https://nodejs.org/dist/latest-v16.x/docs/api/fs.html#fswritefilesyncfile-data-options | ||
* @param {*} options https://nodejs.org/dist/latest-v16.x/docs/api/fs.html#fsreadfilesyncpath-options | ||
* @returns | ||
*/ | ||
const writeFile = async (filePath, fileData, options) => { | ||
const readFile = async (filePath, options) => { | ||
// check | ||
debug('/ writeFile / filePath', filePath); | ||
debug('/ readFile / filePath', filePath); | ||
if (!filePath) return; | ||
try { | ||
// vars | ||
fileData = fileData || ''; | ||
options = options || {}; | ||
debug('/ writeFile / options', options); | ||
// opt | ||
const opt = { encoding: 'utf8' }; | ||
options = options || opt; | ||
debug('/ readFile / options', options); | ||
await fsExtra.outputFile(filePath, fileData, options); | ||
return true; | ||
return await fsExtra.readFile(filePath, options); | ||
} catch (e) { | ||
debug('/ writeFile / fail'); | ||
debug('/ readFile / fail'); | ||
console.log(e); | ||
@@ -346,2 +347,25 @@ } | ||
// readline | ||
/** | ||
* readFileLineByLine | ||
* @param {*} filePath | ||
* @param {*} onLine | ||
* @param {*} onClose | ||
*/ | ||
const readFileLineByLine = (filePath, onLine, onClose) => { | ||
// rl | ||
const rl = readline.createInterface({ | ||
input: fsExtra.createReadStream(filePath, { encoding: 'utf8' }), | ||
}); | ||
// on | ||
rl.on('line', function (line) { | ||
if (onLine) onLine(line); | ||
}); | ||
rl.on('close', function () { | ||
if (onClose) onClose(); | ||
}); | ||
}; | ||
// fs | ||
@@ -369,4 +393,5 @@ | ||
exports.readFile = readFile; | ||
exports.readFileLineByLine = readFileLineByLine; | ||
exports.readdir = readdir; | ||
exports.rm = rm; | ||
exports.writeFile = writeFile; |
{ | ||
"name": "qiao-file", | ||
"version": "3.1.9", | ||
"version": "3.2.3", | ||
"description": "nodejs file tool", | ||
@@ -50,3 +50,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "aa0f42a99110359ea5db659d42d51c3aba9080b0" | ||
"gitHead": "6fd7b780b57bfa8a5389c9fa32e4979be6cdab59" | ||
} |
@@ -18,4 +18,5 @@ // fs & path | ||
export * from './extname.js'; | ||
export * from './write-file.js'; | ||
export * from './read-file.js'; | ||
export * from './write-file.js'; | ||
export * from './read-file-by-line.js'; | ||
@@ -22,0 +23,0 @@ // is |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21909
675