MCPcopy Create free account
hub / github.com/denoland/std / open

Function open

fs/unstable_open.ts:103–139  ·  view source on GitHub ↗
(
  path: string | URL,
  options?: OpenOptions,
)

Source from the content-addressed store, hash-verified

101 * @returns A Promise that resolves to a {@linkcode FsFile} instance.
102 */
103export async function open(
104 path: string | URL,
105 options?: OpenOptions,
106): Promise<FsFile> {
107 if (isDeno) {
108 return Deno.open(path, options);
109 } else {
110 const {
111 read = true,
112 write = false,
113 append = false,
114 truncate = false,
115 create = false,
116 createNew = false,
117 mode = 0o666,
118 } = options ?? {};
119
120 try {
121 const flag = getOpenFsFlag({
122 read,
123 write,
124 append,
125 truncate,
126 create,
127 createNew,
128 });
129 const { open } = getNodeFs();
130 const { promisify } = getNodeUtil();
131 const nodeOpenFd = promisify(open);
132
133 const fd = await nodeOpenFd(path, flag, mode);
134 return new NodeFsFile(fd) as FsFile;
135 } catch (error) {
136 throw mapError(error);
137 }
138 }
139}
140
141/**
142 * Synchronously open a file and return an instance of {@linkcode FsFile}.

Callers 7

createFunction · 0.90

Calls 4

getOpenFsFlagFunction · 0.90
getNodeFsFunction · 0.90
getNodeUtilFunction · 0.90
mapErrorFunction · 0.90

Tested by

no test coverage detected