1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

BREAKING(std/fs): remove readFileStr and readFileStrSync (#6848)

This removes the readFileStr and readFileStrSync functions which are
effectively duplicates of Deno.readTextFile and Deno.readTextFileSync.
This commit is contained in:
Casper Beyer 2020-07-23 10:18:18 +08:00 committed by GitHub
parent 843b54549c
commit fd900cfe21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 70 deletions

View file

@ -1,7 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../testing/asserts.ts";
import { existsSync } from "../fs/exists.ts";
import { readFileStrSync } from "../fs/read_file_str.ts";
import * as path from "../path/mod.ts";
import { parse, stringify } from "./toml.ts";
@ -11,8 +10,7 @@ function parseFile(filePath: string): object {
if (!existsSync(filePath)) {
throw new Error(`File not found: ${filePath}`);
}
const strFile = readFileStrSync(filePath);
return parse(strFile);
return parse(Deno.readTextFileSync(filePath));
}
Deno.test({

View file

@ -168,21 +168,6 @@ async function printFilesNames() {
printFilesNames().then(() => console.log("Done!"));
```
### readFileStr
Read file and output it as a string.
**ReadOptions**
- encoding : The encoding to read file. lowercased.
```ts
import { readFileStr, readFileStrSync } from "https://deno.land/std/fs/mod.ts";
readFileStr("./target.dat", { encoding: "utf8" }); // returns a promise
readFileStrSync("./target.dat", { encoding: "utf8" }); // string
```
### expandGlob
Expand the glob string from the specified `root` directory and yield each result

View file

@ -1,33 +0,0 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
export interface ReadOptions {
encoding?: string;
}
/**
* Read file synchronously and output it as a string.
*
* @param filename File to read
* @param opts Read options
*/
export function readFileStrSync(
filename: string,
opts: ReadOptions = {},
): string {
const decoder = new TextDecoder(opts.encoding);
return decoder.decode(Deno.readFileSync(filename));
}
/**
* Read file and output it as a string.
*
* @param filename File to read
* @param opts Read options
*/
export async function readFileStr(
filename: string,
opts: ReadOptions = {},
): Promise<string> {
const decoder = new TextDecoder(opts.encoding);
return decoder.decode(await Deno.readFile(filename));
}

View file

@ -1,19 +0,0 @@
import { assert } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { readFileStrSync, readFileStr } from "./read_file_str.ts";
const testdataDir = path.resolve("fs", "testdata");
Deno.test("testReadFileSync", function (): void {
const jsonFile = path.join(testdataDir, "json_valid_obj.json");
const strFile = readFileStrSync(jsonFile);
assert(typeof strFile === "string");
assert(strFile.length > 0);
});
Deno.test("testReadFile", async function (): Promise<void> {
const jsonFile = path.join(testdataDir, "json_valid_obj.json");
const strFile = await readFileStr(jsonFile);
assert(typeof strFile === "string");
assert(strFile.length > 0);
});