當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。