本文整理汇总了TypeScript中fs.appendFile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript appendFile函数的具体用法?TypeScript appendFile怎么用?TypeScript appendFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了appendFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: appendFile
return new Promise<void>((resolve, reject) => {
// Do filesystem stuff
const lineStr = `${JSON.stringify(line)}\n`;
appendFile(
joinPath(
'.',
this.dir,
`${this.currentId}.log`,
),
lineStr,
(err) => {
if (err) {
reject(err);
return;
}
resolve();
});
// Add to cache
if (!this.cache.has(this.currentId)) {
this.cache.set(this.currentId, []);
}
const set = this.cache.get(this.currentId);
set.push(line);
if (set.length >= this.maxLogLength) {
this.currentId += 1;
}
});
示例2: function
app.get( '/tracker/1x1/:id', (req, resp, done) => {
fs.appendFile('tracked.txt', req.params.id+',\n', function (err) {
resp.writeHead(200, {'Content-Type': 'image/png' } );
resp.end( trackerPNG );
done();
} );
} );
示例3: resolve
return new Promise<boolean>((resolve, reject) => {
fs.appendFile(path, content, err => {
if (err) return reject(err);
resolve(true);
});
});
示例4: Date
proc.stderr.on('data', data => {
var date = new Date().toLocaleString();
fs.appendFile(`${tempFolder}/errors.log`, `${date}: ${data.toString()}`, (err) => {
if (err) {
throw new Error(`Could not write stderr to errors.log with the following error: ${err}`);
};
});
});
示例5: Promise
return new Promise((resolve: Function, reject: Function): void =>
fs.appendFile(histignoreFile, 'export HISTIGNORE="stymie *:$HISTIGNORE"\n', 'utf8', (err) => {
if (err) {
reject(err);
} else {
resolve('Updated $HISTIGNORE');
}
})
示例6: Date
proc.stderr.on('data', data => {
var date = new Date().toLocaleString();
fs.appendFile(path.join(testDataPath, 'errors.log'), `${date}: ${data.toString()}`, (err) => {
if (err) {
throw new Error(`Could not write stderr to errors.log with the following error: ${err}`);
};
});
});
示例7: save
static save(log: ILogger) {
if (LogFactory.setting.storage == LogStorage.Console) {
console.log(log);
return;
}
fs.appendFile(LogFactory.logFile, `\n${JSON.stringify(log)}`, {encoding: 'utf8'}, err => {
console.error(err);
});
}
示例8: bootstrapSbtProject
).then(choice => {
if (choice === "Yes") {
bootstrapSbtProject(buildSbtFileSource, dottyPluginSbtFileSource)
return Promise.resolve()
} else if (choice === "No") {
fs.appendFile(disableDottyIDEFile, "", _ => {})
return Promise.reject()
}
})
示例9: function
GLOBAL.onError = function (err: any, res:express.Response) {
console.log('onError error\n', err);
//TODO Remove reason in production
res.json({error:'error', reason:err});
var str: string = "\r\n" + new Date().toLocaleString() + "\r\n";
str += JSON.stringify(err);
fs.appendFile(SERVER + '/error.log', str);
};
示例10: updateResponseFile
function updateResponseFile(argsArray: string[], responseFile: string): Q.Promise<string> {
var defer = Q.defer<string>();
fs.appendFile(responseFile, os.EOL + argsArray.join(os.EOL), function (err) {
if (err) {
defer.reject(err);
}
defer.resolve(responseFile);
});
return defer.promise;
}
示例11: writeCSV
function writeCSV(data: any): void {
fs.appendFile("wolfgangsee-pegel.csv", `${data.date}, ${data.level}, ${data.temperature}\n`, (err) => {
if (err) {
console.error("Failed to write file", err);
return;
}
console.log("CSV written successfully");
});
}
示例12: log
export function log(s: string) {
let timed = new Date().toISOString() + "\t" + s;
console.log(timed);
fs.appendFile("./opencode.log", timed + "\n", function (err) {
if (err) {
return console.log("failed to write to log: " + err);
}
});
logtrace.push(timed);
if (logtrace.length > LOG_HISTORY) {
logstart += (logtrace.length - LOG_HISTORY);
logtrace.splice(0, logtrace.length - LOG_HISTORY);
}
}
示例13: function
this.serialPort.on('data', function (line) {
try {
fs.appendFile('gps.txt', line + '\r\n');
var parsedData = nmea.parse(line);
debug('Parsed: ' + JSON.stringify(parsedData));
if (parsedData.hasOwnProperty('lat')) {
self.status.latitude = parsedData.lat / 100;
self.status.longitude = parsedData.lon / 100;
self.status.altitude = parsedData.alt;
}
} catch (err) {
debug('Could not parse: ' + line)
}
});
示例14: setInterval
let id = setInterval(() => {
let timestamp = moment().format('DD/MMM/YYYY:HH:mm:ss Z');
let line = '127.0.0.1 user-identifier frank ['+timestamp+'] "GET /testing/apache_pb.gif HTTP/1.0" 200 2326' + '\n';
if (n === 100){
done();
clearInterval(id);
}
if (Math.random() > 0.7) {
appendFile('test.log', line, (err) => {
if (err) throw err;
n++;
});
}
}, 10);
示例15: fetchAndConfigure
).then(choice => {
if (choice == "Yes") {
fs.readFile(languageServerDefaultConfigFile, (err, data) => {
if (err) throw err
else {
const languageServerScalaVersion = data.toString().trim()
fetchAndConfigure(coursierPath, sbtArtifact, languageServerScalaVersion, dottyPluginSbtFile).then(() => {
runLanguageServer(coursierPath, languageServerArtifactFile)
})
}
})
} else {
fs.appendFile(disableDottyIDEFile, "", _ => {})
}
})