From b71d5708c603b09714a1f539f92f82392b6ee33d Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Wed, 8 Jan 2020 23:07:03 +0100 Subject: feat: Deno.create (#3629) --- cli/js/files.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'cli/js/files.ts') diff --git a/cli/js/files.ts b/cli/js/files.ts index 7f68341bd..1d04c0e70 100644 --- a/cli/js/files.ts +++ b/cli/js/files.ts @@ -39,6 +39,24 @@ export async function open( return new File(rid); } +/** Creates a file if none exists or truncates an existing file and returns + * an instance of the `File` object synchronously. + * + * const file = Deno.createSync("/foo/bar.txt"); + */ +export function createSync(filename: string): File { + return openSync(filename, "w+"); +} + +/** Creates a file if none exists or truncates an existing file and returns + * an instance of the `File` object. + * + * const file = await Deno.create("/foo/bar.txt"); + */ +export function create(filename: string): Promise { + return open(filename, "w+"); +} + /** Read synchronously from a file ID into an array buffer. * * Return `number | EOF` for the operation. @@ -223,11 +241,3 @@ export type OpenMode = | "x" /** Read-write. Behaves like `x` and allows to read from file. */ | "x+"; - -/** A factory function for creating instances of `File` associated with the - * supplied file name. - * @internal - */ -export function create(filename: string): Promise { - return open(filename, "w+"); -} -- cgit v1.2.3