How to use the readFileSync function from fs-extra
Find comprehensive JavaScript fs-extra.readFileSync code examples handpicked from public code repositorys.
439 440 441 442 443 444 445 446 447 448
*/ function addMissingConfiguration() { const templateFolder = path.resolve(__dirname, '..', 'template'); const packageJsonPath = path.join('.', 'package.json'); const templatePackageJson = JSON.parse( fs.readFileSync(path.join(templateFolder, 'package.json'), 'utf8') ); const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); let changed = false;
58
932
20
412 413 414 415 416 417 418 419 420 421
maxEnrollments: -1, enrollmentSecret: 'userpw' }; await caService.register(newUser, admin); const myCsr = fs.readFileSync(path.resolve(__dirname, '../fixtures/fabricca/test.csr'), 'utf8'); const req = { enrollmentID: newUser.enrollmentID, enrollmentSecret: newUser.enrollmentSecret,
522
768
62
+ 27 other calls in file
185 186 187 188 189 190 191 192 193 194
const files = fs.readdirSync(dir); const certs = []; files.forEach((file_name) => { const file_path = path.join(dir, file_name); logger.debug(' looking at file ::' + file_path); const data = fs.readFileSync(file_path); certs.push(data); }); return certs; }
522
768
62
+ 13 other calls in file
458 459 460 461 462 463 464 465 466 467 468
}); gulp.task('validateTelemetry', async () => { const gdprTS = fs.readFileSync(path.join(__dirname, 'src', 'gdpr.ts'), 'utf-8'); await generateTelemetry(); const gdprTS2 = fs.readFileSync(path.join(__dirname, 'src', 'gdpr.ts'), 'utf-8'); if (gdprTS2.trim() !== gdprTS.trim()) { console.error('src/gdpr.ts is not valid, please re-run `npm run generateTelemetry`'); throw new Error('src/gdpr.ts is not valid, please re-run `npm run generateTelemetry`'); }
208
950
43
+ 23 other calls in file
111 112 113 114 115 116 117 118 119 120
uploadTestDataToBucket(config.bucket, s3data, testDataFolder), addCollections(config.stackName, config.bucket, collectionsDir, testSuffix, testId, collectionDupeHandling), apiTestUtils.addProviderApi({ prefix: config.stackName, provider: providerData }), ]); const inputPayloadJson = fs.readFileSync(inputPayloadFilename, 'utf8'); // update test data filepaths inputPayload = await setupTestGranuleForIngest(config.bucket, inputPayloadJson, granuleRegex, testSuffix, testDataFolder); pdrFilename = inputPayload.pdr.name; const granuleId = inputPayload.granules[0].granuleId;
100
223
24
+ 14 other calls in file
GitHub: thumbsup/thumbsup
57 58 59 60 61 62 63 64 65 66 67 68
return exports.file(opts) } exports.fromDisk = function (filename) { const filepath = path.join(__dirname, '..', 'test-fixtures', filename) return fs.readFileSync(filepath) } exports.createTempStructure = function (files) { const tmpdir = tmp.dirSync({ unsafeCleanup: true }).name
80
649
20
+ 9 other calls in file
2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363
}; var safeReadFileSync = toolkit.safeReadFileSync = function(filePath, type) { var data = ''; try { data = fs.readFileSync(filePath).toString(); } catch(err) { console.log(`Reading ${filePath} failed. Origin error:\n${err.toString()}`); }
34
183
6
+ 16 other calls in file
GitHub: 0neGal/viper
76 77 78 79 80 81 82 83 84 85
} } let author_file = path.join(mods.path, file, "thunderstore_author.txt"); if (fs.existsSync(author_file)) { obj.Author = fs.readFileSync(author_file, "utf8"); } if (obj.Disabled) { disabled.push(obj);
17
106
4
+ 22 other calls in file
GitHub: remix-pwa/remix-pwa
70 71 72 73 74 75 76 77 78 79
if (features.includes("Web Manifest")) { integrateManifest(projectDir, lang, dir); } // Register worker in `entry.client.tsx` const remoteClientContent: string = fse.readFileSync(projectDir + `/${dir}/entry.client.` + lang + "x").toString(); const ClientContent = fse.readFileSync(appDir + "/entry.client." + lang).toString(); if (features.includes("Service Workers")) { remoteClientContent.includes(ClientContent)
16
257
5
+ 215 other calls in file
GitHub: nasa/cumulus
81 82 83 84 85 86 87 88 89 90
PG_DATABASE: testDbName, }; const messageConsumer = await awsServices.lambda().createFunction({ Code: { ZipFile: fs.readFileSync(require.resolve('@cumulus/test-data/fake-lambdas/hello.zip')), }, FunctionName: randomId('messageConsumer'), Role: randomId('role'), Handler: 'index.handler',
100
223
23
+ 23 other calls in file
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
var _match = email.html.match(`cid:${_contentid}`); if (_match) { var _data_string; // Read file as base64 if ( _cid === 'base64' ) { var _imageAsBase64 = fs.readFileSync(_attachment_full_path, 'base64'); // Replace _data_string = `data:${attachment.contentType};base64,${_imageAsBase64}`; } else if ( _cid === 'path' ) {
17
28
6
+ 9 other calls in file
1660 1661 1662 1663 1664 1665 1666 1667 1668
var allFiles = this.vlocity.datapacksutils.getFiles(path.join(jobInfo.projectPath, jobInfo.importFolderName)); for (var i = 0; i < allFiles.length; i++) { var basename = allFiles[i]; var dataJson = fs.readFileSync(path.join(jobInfo.projectPath, jobInfo.importFolderName, basename), 'utf8'); try { let result = await this.vlocity.datapacks.import(JSON.parse(dataJson), this.getOptionsFromJobInfo(jobInfo));
80
94
26
+ 35 other calls in file
GitHub: mafiosnik777/enhancr
983 984 985 986 987 988 989 990 991 992 993
} } function changeCodecH264() { try { const jsonString = fs.readFileSync(path.join(__dirname, '..', "/src/codecs.json")); var json = JSON.parse(jsonString); } catch (err) { console.log(err); return;
14
162
7
+ 269 other calls in file
116 117 118 119 120 121 122 123 124 125
if (!fs.existsSync(extDataPath)) { console.log('No ' + packageJson + ' found for: ' + extension); continue; } const content = fs.readFileSync(extDataPath, 'utf-8'); const extData = JSON.parse(content); const extVsixPath = dist(extData.name + '-' + packVersion + '.vsix'); if (!(await isAvailable(extVsixPath, extData.name, packVersion))) {
32
58
15
GitHub: o1-labs/zkapp-cli
257 258 259 260 261 262 263 264 265 266
* @param {string} file - Path to file * @param {string} a - Old text. * @param {string} b - New text. */ function replaceInFile(file, a, b) { let content = fs.readFileSync(file, 'utf8'); content = content.replace(a, b); fs.writeFileSync(file, content); }
29
92
20
+ 103 other calls in file
GitHub: wix-incubator/haste
13 14 15 16 17 18 19 20 21
get: (target, prop) => { const fullPath = path.join(cwd, filename); switch (prop) { case 'content': return fs.readFileSync(fullPath, 'utf8'); case 'exists': return fs.existsSync(fullPath);
10
59
42
248 249 250 251 252 253 254 255 256 257
} avatar(owner) { let afile = this.avatar_path(owner); if (fs.existsSync(afile)) { return fs.readFileSync(afile).toString(); } else { return ""; } }
8
20
4
+ 4 other calls in file
232 233 234 235 236 237 238 239 240 241
return file.indexOf(PART_META_EXT) !== -1; }); let rangeMap = {}; for (const metaPartFile of metaPartFiles) { const metaPartFilePath = path.join(tmpPartPaths, metaPartFile); const content = fs.readFileSync(metaPartFilePath, {encoding: 'utf-8'}); // Range string is of the form "bytes 67108864-100663295/*" const startRange = Number(content.split('-')[0].split(' ')[1].trim()); rangeMap[startRange] = path.join(tmpPartPaths, path.parse(metaPartFilePath).name); }
6
30
1
2284 2285 2286 2287 2288 2289 2290 2291 2292
not_found = true; files[f] = undefined; continue; } let fb = fs.readFileSync(fp); // files[f] = fb.toJSON(); files[f] = fb.toString("binary"); }
5
18
3
+ 44 other calls in file
GitHub: navgurukul/sansaar
315 316 317 318 319 320 321 322 323 324
await this.addAssessment(updatingData); } else { if (data.name !== undefined) { data.name = `${exerciseDetails.name}_${data.name}`; if (fs.existsSync(`${courseFolderName}`)) { const courseData = fs.readFileSync( `${courseFolderName}/${assessmentData.name}.json` ); const allJsonData = courseData.toString().trim(); fs.renameSync(
18
15
4
+ 15 other calls in file
fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)