diff options
author | Casper Beyer <caspervonb@pm.me> | 2021-02-02 19:05:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-02 12:05:46 +0100 |
commit | 6abf126c2a7a451cded8c6b5e6ddf1b69c84055d (patch) | |
tree | fd94c013a19fcb38954844085821ec1601c20e18 /std/node/_fs/_fs_open.ts | |
parent | a2b5d44f1aa9d64f448a2a3cc2001272e2f60b98 (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_open.ts')
-rw-r--r-- | std/node/_fs/_fs_open.ts | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/std/node/_fs/_fs_open.ts b/std/node/_fs/_fs_open.ts deleted file mode 100644 index 55ecbdc1e..000000000 --- a/std/node/_fs/_fs_open.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { existsSync } from "../../fs/mod.ts"; -import { fromFileUrl } from "../path.ts"; -import { getOpenOptions } from "./_fs_common.ts"; - -type openFlags = - | "a" - | "ax" - | "a+" - | "ax+" - | "as" - | "as+" - | "r" - | "r+" - | "rs+" - | "w" - | "wx" - | "w+" - | "wx+"; - -type openCallback = (err: Error | null, fd: number) => void; - -function convertFlagAndModeToOptions( - flag?: openFlags, - mode?: number, -): Deno.OpenOptions | undefined { - if (!flag && !mode) return undefined; - if (!flag && mode) return { mode }; - return { ...getOpenOptions(flag), mode }; -} - -export function open(path: string | URL, callback: openCallback): void; -export function open( - path: string | URL, - flags: openFlags, - callback: openCallback, -): void; -export function open( - path: string | URL, - flags: openFlags, - mode: number, - callback: openCallback, -): void; -export function open( - path: string | URL, - flagsOrCallback: openCallback | openFlags, - callbackOrMode?: openCallback | number, - maybeCallback?: openCallback, -) { - const flags = typeof flagsOrCallback === "string" - ? flagsOrCallback - : undefined; - const callback = typeof flagsOrCallback === "function" - ? flagsOrCallback - : typeof callbackOrMode === "function" - ? callbackOrMode - : maybeCallback; - const mode = typeof callbackOrMode === "number" ? callbackOrMode : undefined; - path = path instanceof URL ? fromFileUrl(path) : path; - - if (!callback) throw new Error("No callback function supplied"); - - if (["ax", "ax+", "wx", "wx+"].includes(flags || "") && existsSync(path)) { - const err = new Error(`EEXIST: file already exists, open '${path}'`); - (callback as (err: Error) => void)(err); - } else { - if (flags === "as" || flags === "as+") { - let err: Error | null = null, res: number; - try { - res = openSync(path, flags, mode); - } catch (error) { - err = error; - } - if (err) { - (callback as (err: Error) => void)(err); - } else { - callback(null, res!); - } - return; - } - Deno.open(path, convertFlagAndModeToOptions(flags, mode)).then( - (file) => callback(null, file.rid), - (err) => (callback as (err: Error) => void)(err), - ); - } -} - -export function openSync(path: string | URL): number; -export function openSync(path: string | URL, flags?: openFlags): number; -export function openSync(path: string | URL, mode?: number): number; -export function openSync( - path: string | URL, - flags?: openFlags, - mode?: number, -): number; -export function openSync( - path: string | URL, - flagsOrMode?: openFlags | number, - maybeMode?: number, -) { - const flags = typeof flagsOrMode === "string" ? flagsOrMode : undefined; - const mode = typeof flagsOrMode === "number" ? flagsOrMode : maybeMode; - path = path instanceof URL ? fromFileUrl(path) : path; - - if (["ax", "ax+", "wx", "wx+"].includes(flags || "") && existsSync(path)) { - throw new Error(`EEXIST: file already exists, open '${path}'`); - } - - return Deno.openSync(path, convertFlagAndModeToOptions(flags, mode)).rid; -} |