Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
zekth committed Mar 19, 2019
1 parent 87e3740 commit 7a98eda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions fs/read_file.ts → fs/read_file_str.ts
Expand Up @@ -10,7 +10,10 @@ export interface ReadOptions {
* @param filename File to read
* @param opts Read options
*/
export function readFileSync(filename: string, opts: ReadOptions = {}): string {
export function readFileStrSync(
filename: string,
opts: ReadOptions = {}
): string {
const decoder = new TextDecoder(opts.encoding);
return decoder.decode(Deno.readFileSync(filename));
}
Expand All @@ -21,7 +24,7 @@ export function readFileSync(filename: string, opts: ReadOptions = {}): string {
* @param filename File to read
* @param opts Read options
*/
export async function readFile(
export async function readFileStr(
filename: string,
opts: ReadOptions = {}
): Promise<string> {
Expand Down
6 changes: 3 additions & 3 deletions fs/read_file_test.ts → fs/read_file_str_test.ts
@@ -1,20 +1,20 @@
import { test } from "../testing/mod.ts";
import { assert } from "../testing/asserts.ts";
import { readFileSync, readFile } from "./read_file.ts";
import { readFileStrSync, readFileStr } from "./read_file_str.ts";
import * as path from "./path/mod.ts";

const testdataDir = path.resolve("fs", "testdata");

test(function testReadFileSync() {
const jsonFile = path.join(testdataDir, "json_valid_obj.json");
const strFile = readFileSync(jsonFile);
const strFile = readFileStrSync(jsonFile);
assert(typeof strFile === "string");
assert(strFile.length > 0);
});

test(async function testReadFile() {
const jsonFile = path.join(testdataDir, "json_valid_obj.json");
const strFile = await readFile(jsonFile);
const strFile = await readFileStr(jsonFile);
assert(typeof strFile === "string");
assert(strFile.length > 0);
});

0 comments on commit 7a98eda

Please sign in to comment.