Add mode option to open/create (#4289)

This commit is contained in:
dubiousjim 2020-03-16 15:02:41 -04:00 committed by GitHub
parent 8077ade741
commit f9557a4ff6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 27 deletions

View file

@ -22,43 +22,47 @@ import {
} from "./ops/fs/open.ts";
export { OpenOptions, OpenMode } from "./ops/fs/open.ts";
export function openSync(path: string, mode?: OpenOptions): File;
export function openSync(path: string, mode?: OpenMode): File;
export function openSync(path: string, options?: OpenOptions): File;
export function openSync(path: string, openMode?: OpenMode): File;
/**@internal*/
export function openSync(
path: string,
modeOrOptions: OpenOptions | OpenMode = "r"
): File {
let mode = undefined;
let openMode = undefined;
let options = undefined;
if (typeof modeOrOptions === "string") {
mode = modeOrOptions;
openMode = modeOrOptions;
} else {
checkOpenOptions(modeOrOptions);
options = modeOrOptions as OpenOptions;
}
const rid = opOpenSync(path, mode as OpenMode, options);
const rid = opOpenSync(path, openMode as OpenMode, options);
return new File(rid);
}
export async function open(path: string, options?: OpenOptions): Promise<File>;
export async function open(path: string, mode?: OpenMode): Promise<File>;
export async function open(path: string, openMode?: OpenMode): Promise<File>;
/**@internal*/
export async function open(
path: string,
modeOrOptions: OpenOptions | OpenMode = "r"
): Promise<File> {
let mode = undefined;
let openMode = undefined;
let options = undefined;
if (typeof modeOrOptions === "string") {
mode = modeOrOptions;
openMode = modeOrOptions;
} else {
checkOpenOptions(modeOrOptions);
options = modeOrOptions as OpenOptions;
}
const rid = await opOpen(path, mode as OpenMode, options);
const rid = await opOpen(path, openMode as OpenMode, options);
return new File(rid);
}