diff options
author | Divya <hello@shortdiv.com> | 2020-04-28 00:35:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-28 01:35:20 -0400 |
commit | de751e5221cd2eafbdd9cddfb58b0619d74c0504 (patch) | |
tree | 10af8c5b70fc6b57f4a3247ec3367bf5847f195b /cli/js/lib.deno.ns.d.ts | |
parent | 2fc5878668d8f08ec6989d07e79125d640a73d43 (diff) |
fix(#4769) Adds readTextFile, writeTextFile, with sync counterparts (#4901)
Diffstat (limited to 'cli/js/lib.deno.ns.d.ts')
-rw-r--r-- | cli/js/lib.deno.ns.d.ts | 37 |
1 files changed, 37 insertions, 0 deletions
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<void>; + /** 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<string>; + /** 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<void>; + /** 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<void>; + /** **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 |