summaryrefslogtreecommitdiff
path: root/std/node/_fs/_fs_writeFile.ts
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-02-02 19:05:46 +0800
committerGitHub <noreply@github.com>2021-02-02 12:05:46 +0100
commit6abf126c2a7a451cded8c6b5e6ddf1b69c84055d (patch)
treefd94c013a19fcb38954844085821ec1601c20e18 /std/node/_fs/_fs_writeFile.ts
parenta2b5d44f1aa9d64f448a2a3cc2001272e2f60b98 (diff)
chore: remove std directory (#9361)
This removes the std folder from the tree. Various parts of the tests are pretty tightly dependent on std (47 direct imports and 75 indirect imports, not counting the cli tests that use them as fixtures) so I've added std as a submodule for now.
Diffstat (limited to 'std/node/_fs/_fs_writeFile.ts')
-rw-r--r--std/node/_fs/_fs_writeFile.ts113
1 files changed, 0 insertions, 113 deletions
diff --git a/std/node/_fs/_fs_writeFile.ts b/std/node/_fs/_fs_writeFile.ts
deleted file mode 100644
index e68bd8884..000000000
--- a/std/node/_fs/_fs_writeFile.ts
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-import { Encodings, notImplemented } from "../_utils.ts";
-import { fromFileUrl } from "../path.ts";
-import { Buffer } from "../buffer.ts";
-import {
- CallbackWithError,
- checkEncoding,
- getEncoding,
- getOpenOptions,
- isFileOptions,
- WriteFileOptions,
-} from "./_fs_common.ts";
-
-export function writeFile(
- pathOrRid: string | number | URL,
- data: string | Uint8Array,
- optOrCallback: Encodings | CallbackWithError | WriteFileOptions | undefined,
- callback?: CallbackWithError,
-): void {
- const callbackFn: CallbackWithError | undefined =
- optOrCallback instanceof Function ? optOrCallback : callback;
- const options: Encodings | WriteFileOptions | undefined =
- optOrCallback instanceof Function ? undefined : optOrCallback;
-
- if (!callbackFn) {
- throw new TypeError("Callback must be a function.");
- }
-
- pathOrRid = pathOrRid instanceof URL ? fromFileUrl(pathOrRid) : pathOrRid;
-
- const flag: string | undefined = isFileOptions(options)
- ? options.flag
- : undefined;
-
- const mode: number | undefined = isFileOptions(options)
- ? options.mode
- : undefined;
-
- const encoding = checkEncoding(getEncoding(options)) || "utf8";
- const openOptions = getOpenOptions(flag || "w");
-
- if (typeof data === "string") data = Buffer.from(data, encoding);
-
- const isRid = typeof pathOrRid === "number";
- let file;
-
- let error: Error | null = null;
- (async (): Promise<void> => {
- try {
- file = isRid
- ? new Deno.File(pathOrRid as number)
- : await Deno.open(pathOrRid as string, openOptions);
-
- if (!isRid && mode) {
- if (Deno.build.os === "windows") notImplemented(`"mode" on Windows`);
- await Deno.chmod(pathOrRid as string, mode);
- }
-
- await Deno.writeAll(file, data as Uint8Array);
- } catch (e) {
- error = e;
- } finally {
- // Make sure to close resource
- if (!isRid && file) file.close();
- callbackFn(error);
- }
- })();
-}
-
-export function writeFileSync(
- pathOrRid: string | number | URL,
- data: string | Uint8Array,
- options?: Encodings | WriteFileOptions,
-): void {
- pathOrRid = pathOrRid instanceof URL ? fromFileUrl(pathOrRid) : pathOrRid;
-
- const flag: string | undefined = isFileOptions(options)
- ? options.flag
- : undefined;
-
- const mode: number | undefined = isFileOptions(options)
- ? options.mode
- : undefined;
-
- const encoding = checkEncoding(getEncoding(options)) || "utf8";
- const openOptions = getOpenOptions(flag || "w");
-
- if (typeof data === "string") data = Buffer.from(data, encoding);
-
- const isRid = typeof pathOrRid === "number";
- let file;
-
- let error: Error | null = null;
- try {
- file = isRid
- ? new Deno.File(pathOrRid as number)
- : Deno.openSync(pathOrRid as string, openOptions);
-
- if (!isRid && mode) {
- if (Deno.build.os === "windows") notImplemented(`"mode" on Windows`);
- Deno.chmodSync(pathOrRid as string, mode);
- }
-
- Deno.writeAllSync(file, data as Uint8Array);
- } catch (e) {
- error = e;
- } finally {
- // Make sure to close resource
- if (!isRid && file) file.close();
-
- if (error) throw error;
- }
-}