From de751e5221cd2eafbdd9cddfb58b0619d74c0504 Mon Sep 17 00:00:00 2001 From: Divya Date: Tue, 28 Apr 2020 00:35:20 -0500 Subject: fix(#4769) Adds readTextFile, writeTextFile, with sync counterparts (#4901) --- cli/js/lib.deno.ns.d.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'cli/js/lib.deno.ns.d.ts') diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts index d33fde844..6d354d034 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -1276,6 +1276,25 @@ declare namespace Deno { * Requires `allow-read` and `allow-write` permission. */ export function rename(oldpath: string, newpath: string): Promise; + /** Synchronously reads and returns the entire contents of a file as utf8 encoded string + * encoded string. Reading a directory returns an empty string. + * + * const data = Deno.readTextFileSync("hello.txt"); + * console.log(data); + * + * Requires `allow-read` permission. */ + export function readTextFileSync(path: string): string; + + /** Asynchronously reads and returns the entire contents of a file as a utf8 + * encoded string. Reading a directory returns an empty data array. + * + * const decoder = new TextDecoder("utf-8"); + * const data = Deno.readFileSync("hello.txt"); + * console.log(decoder.decode(data)); + * + * Requires `allow-read` permission. */ + export function readTextFile(path: string): Promise; + /** Synchronously reads and returns the entire contents of a file as an array * of bytes. `TextDecoder` can be used to transform the bytes to string if * required. Reading a directory returns an empty data array. @@ -1598,6 +1617,24 @@ declare namespace Deno { options?: WriteFileOptions ): Promise; + /** Synchronously write string `data` to the given `path`, by default creating a new file if needed, + * else overwriting. + * + * await Deno.writeTextFileSync("hello1.txt", "Hello world\n"); // overwrite "hello1.txt" or create it + * + * Requires `allow-write` permission, and `allow-read` if `options.create` is `false`. + */ + export function writeTextFileSync(path: string, data: string): void; + + /** Asynchronously write string `data` to the given `path`, by default creating a new file if needed, + * else overwriting. + * + * await Deno.writeTextFile("hello1.txt", "Hello world\n"); // overwrite "hello1.txt" or create it + * + * Requires `allow-write` permission, and `allow-read` if `options.create` is `false`. + */ + export function writeTextFile(path: string, data: string): Promise; + /** **UNSTABLE**: Should not have same name as `window.location` type. */ interface Location { /** The full url for the module, e.g. `file://some/file.ts` or -- cgit v1.2.3