本文整理汇总了TypeScript中fs.writeFile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript writeFile函数的具体用法?TypeScript writeFile怎么用?TypeScript writeFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了writeFile函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: reject
fs.readFile(fileName, { encoding }, (err, fileText) => {
/* istanbul ignore if */
if (err) {
reject(err);
return;
}
const result = replaceInText(fileName, fileText);
if (result.replaced) {
fs.writeFile(fileName, result.fileText!, writeErr => {
/* istanbul ignore if */
if (writeErr) {
reject(writeErr);
return;
}
resolve();
});
}
else {
resolve();
}
});
示例2: LoginReceiver
function LoginReceiver(msg) {
console.log(msg);
$("#user").prop('disabled', true);
$("#password").prop('disabled', true);
//alert(JSON.stringify(msg));
if (msg.type == connect.MessageType.RESPONSE) {
if (msg.content.type == connect.MessageType.LOGIN) {
if (msg.content.code == connect.ResponseCode.INVALID_LOGIN_INFO) {
ipcRenderer.send('loadWindow', 2);
alert("Los datos ingresados no son correctos!");
}
else if(msg.content.code == connect.ResponseCode.OK) {
var rooms = {"rooms": msg.content.content};
ipcRenderer.send('loadWindow', 3);
fs.writeFile(__dirname + '/../../tmp/rooms.json', JSON.stringify(rooms, null, 4));
//ipcRenderer.send('updateFile', {"data": msg.content.content, "type": "rooms"});
}
}
console.log("Respuesta para:", connect.MessageType[msg.content.type]);
console.log("Codigo de respuesta:", connect.ResponseCode[msg.content.code]);
}
}
示例3: adjacency_list_to_dot
export function adjacency_list_to_dot(adj_list, output_path) {
var fs = require('fs');
var path = require('path');
var child_process = require('child_process'); // to call dotty
var output = 'digraph G {\n'
for (var vertex in adj_list) {
output += '\t"' + vertex.replace(/"/g, "'") + '"';
var parents = adj_list[vertex];
for (var i=0; i<parents.length; ++i)
output += ' -> "' + parents[i].replace(/"/g, "'") + '"';
output += ';\n';
}
output += '}';
var output_dir = path.dirname(output_path);
var filename = path.basename(output_path);
var extension = path.extname(output_path).replace(/\./g, "");
var dot_file = path.join(output_dir, filename.replace(extension, 'dot'));
fs.writeFile(dot_file, output, function (err) {
if (err) throw err;
});
var path_to_dot = '"C:\\Program Files (x86)\\Graphviz2.38\\bin\\dot.exe"'
var cmd = path_to_dot + " -T" + extension + ' ' + dot_file + ' -o ' + output_path;
child_process.exec(cmd, function(error, stdout, stderr) {
//dbg('stdout', stdout);
//dbg('stderr', stderr);
if (stderr) {
throw stderr;
} else {
info_msg(output_path + " successfully created !");
}
});
}
示例4:
remote.getCurrentWindow().capturePage(buf => {
fs.writeFile('/tmp/screenshot.png', buf, err => {
console.log(err);
});
});
示例5: writeFile
call_back =>
writeFile(path_join(...dir_file), 'exports.bar = function(){}', 'utf8', call_back)
示例6: generateNamespace
import { generateNamespace } from "@gql2ts/from-schema";
import { genSchema } from '../utils/generateSchema';
import * as path from "path";
import * as fs from 'fs';
const typescriptTypes = generateNamespace('GQL', genSchema());
fs.writeFile(
path.join(__dirname, '../types/schema.d.ts'),
typescriptTypes,
(err) => console.log(err)
);
示例7: reject
.then(() => fs.writeFile(file, data, /*encoding*/ "utf8", err => err ? reject(err) : resolve()))
示例8: ls
'<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n';
function ls(path) {
const files: string[] = fs.readdirSync(path);
const prefix: string = (path.length > 2 ? path + '/' : './');
for (const file of files) {
const fname: string = prefix + file;
const stat: fs.Stats = fs.statSync(fname);
if (stat.isFile()) {
if (file.endsWith('.htm') ||
file.endsWith('.html')) {
const mtime: string = dateFormat('yyyy-MM-dd', stat.mtime);
out += '<url><loc>' + domain + fname.substring(1) +
'</loc><lastmod>' + mtime + '</lastmod></url>\n';
}
} else if (stat.isDirectory()) {
ls(fname);
}
}
}
try {
ls('./');
out += '</urlset>';
fs.writeFile('./sitemap.xml', out, (err: NodeJS.ErrnoException): void => {
if (err) { throw err; }
});
} catch (e) {
console.error(e);
}
示例9: saveGame
export function saveGame() {
writeFile("game.sav", "0.1;" + configSaver(), (err) => {
throw err;
});
}
示例10:
res.on('end', () => {
fs.writeFile(location, Buffer.concat(buffer), 'utf8', () => {
console.log('Keybindings were successfully fetched.');
resolve();
});
});