本文整理匯總了TypeScript中fs-promise.readFile函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript readFile函數的具體用法?TypeScript readFile怎麽用?TypeScript readFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了readFile函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: checkPage
async function checkPage(beforePath: string, afterPath: string) {
const before = new JSDOM(await fs.readFile(beforePath))
const after = new JSDOM(await fs.readFile(afterPath))
const replacer = createReplacer()
await replacer.replace(before.window.document as Node)
assert.strictEqual(before.window.document.body.textContent, after.window.document.body.textContent)
}
示例2: readFile
public async readFile(path: string, resourceType: ResourceType): Promise<Object> {
let data: Object = { };
try {
let str: string = await fs.readFile(path + ".meta", "utf8");
data = yaml.safeLoad(str);
}
catch (err) {
// There isn't a meta file...
}
data["body"] = await fs.readFile(path);
return data;
}
示例3: async
const resetTestModule = async () => {
await fs.remove(testModulePath);
await fs.mkdirs(testModulePath);
await fs.writeFile(path.resolve(testModulePath, 'package.json'), await fs.readFile(path.resolve(__dirname, '../test/fixture/native-app1/package.json'), 'utf8'));
await spawnPromise('npm', ['install'], {
cwd: testModulePath,
stdio: 'inherit',
});
};
示例4: readFile
public async readFile(path: string, resourceType: ResourceType): Promise<Object> {
let parseFrontmatter = !!resourceType ? resourceType.parseFrontmatter : true;
let encoding = resolveEncoding(resourceType);
let str = await fs.readFile(path, encoding);
let data = this.readString(str, parseFrontmatter);
// Allow frontmatter of resource to override the resource's output encoding.
data["_encoding"] = data["_encoding"] || encoding;
return data;
}
示例5: getFileData
export function getFileData(filePath: string): Q.Promise<any[]> {
return fs.readFile(filePath, 'utf-8').then((fileData) => {
try {
return parseData(fileData, path.extname(filePath));
} catch (e) {
throw new Error(`could not parse '${filePath}': ${e.message}`);
}
}).then((fileJSON) => {
fileJSON.forEach((d: PseudoDatum) => {
d['time'] = new Date(d['time']);
});
return fileJSON;
});
}
示例6: readPackageJson
export async function readPackageJson(dir: string, safe = false) {
let packageData;
try {
packageData = await fs.readFile(path.resolve(dir, 'package.json'), 'utf8');
} catch (err) {
if (safe) {
packageData = '{}';
} else {
throw err;
}
}
return JSON.parse(packageData);
};
示例8: fromSourceFile
/**
* Initializes a new instance of the SourceFilePrinter class.
*
* @param sourceFile The source file to be printed.
* @param settings Settings to run Typespace.
* @returns A promise for a new instance of the SourceFilePrinter class.
*/
public static async fromSourceFile(sourceFile: SourceFile, settings: ITypespaceSettings): Promise<SourceFilePrinter> {
return new SourceFilePrinter(
sourceFile,
(await fs.readFile(sourceFile.fullPath)).toString(),
settings);
}
示例9:
const files = await Promise.all(paths.map((path: String) => fs.readFile(`docs/${path}`, 'utf8')));
示例10: createFileContentItemForPath
async function createFileContentItemForPath(rootDirectory: string, relativePath: string): Promise<ContentItem> {
const fullPath = path.join(rootDirectory, relativePath);
const content = await fsp.readFile(fullPath, UTF8);
return new ContentItemBuilder(false, relativePath)
.withContent(content).build();
}