function overwriteFile (path, onInputRead) { try { fs.closeSync(fs.openSync(path, 'a+')) // if the file doesn't exist, create it const encoding = 'utf-8' fs.writeFileSync(path, onInputRead(fs.readFileSync(path, encoding)), encoding) } catch (error) { console.error(`error writing ${path}, error: ${error}`) } }
/** * Clears the data.json file and starts to aggregate the data on the FHIR server */ function aggregate() { if (!fs.existsSync(APP.outputFile)) { fs.closeSync(fs.openSync(APP.outputFile, 'w')); } fs.writeFileSync(APP.outputFile, '{"tags": []}'); lib.getAllResources(lib.buildFhirURL(APP.server, 'Patient', ['_count=50']), handlePatientData); getDataForResourceTable(config.TAGS); }
process.on('exit',function(code){ if (entries.length>0) { console.log('Writing '+entries.length+' new entries'); entry_str = ''; for (var i in entries) { entry_str += entries[i]+'\n'; } dlh_fh = fs.openSync(dlh_locn,'a'); fs.appendFileSync(dlh_locn, entry_str, 'utf8'); fs.closeSync(dlh_fh); } });
//----------------------------------------------------------------------------- function append_newstr() { if (newstr.length>0) { console.log('Writing '+newstr.length+' entries'); entry_str = ''; for (var i in newstr) { entry_str += newstr[i]+'\n'; } dlh_fh = fs.openSync(dlh_locn,'a'); fs.appendFileSync(dlh_locn, entry_str, 'utf8'); fs.closeSync(dlh_fh); } }
describe('findCode', () => { it('finds Code in path', () => { const cwdIntermediaryTempDir = path.join(tempdir, 'a', 'b', 'c'); const codeTempDir = path.join(cwdIntermediaryTempDir, codeDirName); mkdirp(codeTempDir); const codeTempFile = normalizeForWindows(path.join(codeTempDir, ccodeBinName)); fs.closeSync(fs.openSync(codeTempFile, 'w')); const cwdDir = path.join(cwdIntermediaryTempDir, 'd', 'e', 'f'); mkdirp(cwdDir); process.chdir(cwdDir); const [codeFound, codePath] = findCode(); codeFound.should.be.true; if (isTravisOnAMac) codePath.should.endWith(codeTempFile); // travis adds /private to the base dir else codePath.should.equal(codeTempFile); }); });
process.on('beforeExit', (code) => { fs.closeSync(fd); obs.close(); });
close() { fs.closeSync(this.fd); }
function createSampleFileSync(sampleFilePath){ if(!fs.existsSync(sampleFilePath)){ mkdirsSync(pathLib.dirname(sampleFilePath)); var fd = fs.openSync(sampleFilePath, 'w'); if(fd){ for(let i=0;i < 1000000;i++){ fs.writeSync(fd, String(Math.random()) + '\n'); fs.writeSync(fd, String(Math.random()) + '\n'); fs.writeSync(fd, String(Math.random()) + '\n'); fs.writeSync(fd, String(Math.random()) + '\n'); } fs.closeSync(fd); } } return sampleFilePath; }
const rewriteCronFile = (jobs) => { const cronFilePath = './.node-persist/jobs.crontab'; if (fs.existsSync(cronFilePath)) { fs.unlinkSync(cronFilePath); } fs.closeSync(fs.openSync(cronFilePath, 'w')); jobs.forEach(job => { if (job.active) { let cronEntry = makeCommand(job) + ` >> /var/log/${job.name}.log 2>&1 \n`; fs.appendFileSync(cronFilePath, cronEntry); } }); restartCron(); }
close() { fs.closeSync(this.handle) }
// number of tests currently running var touch = function(fileName) { fs.closeSync(fs.openSync(fileName, 'w')); }
close() { fs.closeSync(this.fd); }
// number of tests currently running var touch = function(fileName) { fs.closeSync(fs.openSync(fileName, 'w')); }
function createSampleFileSync(sampleFilePath){ if(!fs.existsSync(sampleFilePath)){ mkdirsSync(pathLib.dirname(sampleFilePath)); var fd = fs.openSync(sampleFilePath, 'w'); if(fd){ fs.writeSync(fd, String(Math.random()) + '\n'); fs.writeSync(fd, String(Math.random()) + '\n'); fs.writeSync(fd, String(Math.random()) + '\n'); fs.writeSync(fd, String(Math.random()) + '\n'); fs.closeSync(fd); } } return sampleFilePath; }
function createSampleFileSync(sampleFilePath){ if(!fs.existsSync(sampleFilePath)){ mkdirsSync(pathLib.dirname(sampleFilePath)); var fd = fs.openSync(sampleFilePath, 'w'); if(fd){ fs.writeSync(fd, String(Math.random()) + '\n'); fs.writeSync(fd, String(Math.random()) + '\n'); fs.writeSync(fd, String(Math.random()) + '\n'); fs.writeSync(fd, String(Math.random()) + '\n'); fs.closeSync(fd); } } return sampleFilePath; }