mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
BREAKING(std/fs): remove writeFileStr and writeFileStrSync (#6847)
This removes the writeFileStr and writeFileStrSync functions which are effectivly duplicates of Deno.writeTextFile and Deno.writeTextFileSync.
This commit is contained in:
parent
b573bbe447
commit
843b54549c
3 changed files with 0 additions and 79 deletions
|
@ -183,20 +183,6 @@ readFileStr("./target.dat", { encoding: "utf8" }); // returns a promise
|
|||
readFileStrSync("./target.dat", { encoding: "utf8" }); // string
|
||||
```
|
||||
|
||||
### writeFileStr
|
||||
|
||||
Write the string to file.
|
||||
|
||||
```ts
|
||||
import {
|
||||
writeFileStr,
|
||||
writeFileStrSync,
|
||||
} from "https://deno.land/std/fs/mod.ts";
|
||||
|
||||
writeFileStr("./target.dat", "file content"); // returns a promise
|
||||
writeFileStrSync("./target.dat", "file content"); // void
|
||||
```
|
||||
|
||||
### expandGlob
|
||||
|
||||
Expand the glob string from the specified `root` directory and yield each result
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
/**
|
||||
* Write the string to file synchronously.
|
||||
*
|
||||
* @param filename File to write
|
||||
* @param content The content write to file
|
||||
* @returns void
|
||||
*/
|
||||
export function writeFileStrSync(filename: string, content: string): void {
|
||||
const encoder = new TextEncoder();
|
||||
Deno.writeFileSync(filename, encoder.encode(content));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the string to file.
|
||||
*
|
||||
* @param filename File to write
|
||||
* @param content The content write to file
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
export async function writeFileStr(
|
||||
filename: string,
|
||||
content: string,
|
||||
): Promise<void> {
|
||||
const encoder = new TextEncoder();
|
||||
await Deno.writeFile(filename, encoder.encode(content));
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
import { assertEquals } from "../testing/asserts.ts";
|
||||
import * as path from "../path/mod.ts";
|
||||
import { writeFileStr, writeFileStrSync } from "./write_file_str.ts";
|
||||
|
||||
const testdataDir = path.resolve("fs", "testdata");
|
||||
|
||||
Deno.test("testReadFileSync", function (): void {
|
||||
const jsonFile = path.join(testdataDir, "write_file_1.json");
|
||||
const content = "write_file_str_test";
|
||||
writeFileStrSync(jsonFile, content);
|
||||
|
||||
// make sure file have been create.
|
||||
Deno.statSync(jsonFile);
|
||||
|
||||
const result = new TextDecoder().decode(Deno.readFileSync(jsonFile));
|
||||
|
||||
// remove test file
|
||||
Deno.removeSync(jsonFile);
|
||||
|
||||
assertEquals(content, result);
|
||||
});
|
||||
|
||||
Deno.test("testReadFile", async function (): Promise<void> {
|
||||
const jsonFile = path.join(testdataDir, "write_file_2.json");
|
||||
const content = "write_file_str_test";
|
||||
await writeFileStr(jsonFile, content);
|
||||
|
||||
// make sure file have been create.
|
||||
await Deno.stat(jsonFile);
|
||||
|
||||
const result = new TextDecoder().decode(await Deno.readFile(jsonFile));
|
||||
|
||||
// remove test file
|
||||
await Deno.remove(jsonFile);
|
||||
|
||||
assertEquals(content, result);
|
||||
});
|
Loading…
Reference in a new issue