当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript fs-promise.readFile函数代码示例

本文整理汇总了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)
}
开发者ID:cgrail,项目名称:github-chrome-fullname,代码行数:8,代码来源:replacer.ts

示例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;
  }
开发者ID:webreed,项目名称:webreed-binary-mode,代码行数:14,代码来源:BinaryMode.ts

示例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',
   });
 };
开发者ID:our-city-app,项目名称:mobicage-desktop-client,代码行数:9,代码来源:rebuild.ts

示例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;
  }
开发者ID:webreed,项目名称:webreed-text-mode,代码行数:12,代码来源:TextMode.ts

示例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;
  });
}
开发者ID:coconutpalm,项目名称:pivot,代码行数:14,代码来源:executor.ts

示例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);
};
开发者ID:our-city-app,项目名称:mobicage-desktop-client,代码行数:14,代码来源:read-package-json.ts

示例7:

 .then(() => fsp.readFile(filePath))
开发者ID:juliusl,项目名称:intern-assassins,代码行数:1,代码来源:server.ts

示例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);
 }
开发者ID:JoshuaKGoldberg,项目名称:Typespace,代码行数:13,代码来源:SourceFilePrinter.ts

示例9:

 const files = await Promise.all(paths.map((path: String) => fs.readFile(`docs/${path}`, 'utf8')));
开发者ID:sagacite2,项目名称:test-koa-typescript,代码行数:1,代码来源:4.ts

示例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();
}
开发者ID:mjwbenton,项目名称:staircase-generator,代码行数:6,代码来源:site.ts


注:本文中的fs-promise.readFile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。