mirror of
https://github.com/denoland/deno.git
synced 2025-09-23 02:42:34 +00:00
Rename name/filename arguments to path (#4227)
There's a lot of variation in doc comments and internal code about whether the first parameter to file system calls is `path` or `name` or `filename`. For consistency, have made it always be `path`.
This commit is contained in:
parent
bb3d9c8280
commit
acf0958e94
10 changed files with 111 additions and 114 deletions
|
@ -26,7 +26,7 @@ export interface WriteFileOptions {
|
|||
* Requires `allow-write` permission, and `allow-read` if create is `false`.
|
||||
*/
|
||||
export function writeFileSync(
|
||||
filename: string,
|
||||
path: string,
|
||||
data: Uint8Array,
|
||||
options: WriteFileOptions = {}
|
||||
): void {
|
||||
|
@ -34,15 +34,15 @@ export function writeFileSync(
|
|||
const create = !!options.create;
|
||||
if (!create) {
|
||||
// verify that file exists
|
||||
statSync(filename);
|
||||
statSync(path);
|
||||
}
|
||||
}
|
||||
|
||||
const openMode = !!options.append ? "a" : "w";
|
||||
const file = openSync(filename, openMode);
|
||||
const file = openSync(path, openMode);
|
||||
|
||||
if (options.perm !== undefined && options.perm !== null) {
|
||||
chmodSync(filename, options.perm);
|
||||
chmodSync(path, options.perm);
|
||||
}
|
||||
|
||||
writeAllSync(file, data);
|
||||
|
@ -59,7 +59,7 @@ export function writeFileSync(
|
|||
* Requires `allow-write` permission, and `allow-read` if create is `false`.
|
||||
*/
|
||||
export async function writeFile(
|
||||
filename: string,
|
||||
path: string,
|
||||
data: Uint8Array,
|
||||
options: WriteFileOptions = {}
|
||||
): Promise<void> {
|
||||
|
@ -67,15 +67,15 @@ export async function writeFile(
|
|||
const create = !!options.create;
|
||||
if (!create) {
|
||||
// verify that file exists
|
||||
await stat(filename);
|
||||
await stat(path);
|
||||
}
|
||||
}
|
||||
|
||||
const openMode = !!options.append ? "a" : "w";
|
||||
const file = await open(filename, openMode);
|
||||
const file = await open(path, openMode);
|
||||
|
||||
if (options.perm !== undefined && options.perm !== null) {
|
||||
await chmod(filename, options.perm);
|
||||
await chmod(path, options.perm);
|
||||
}
|
||||
|
||||
await writeAll(file, data);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue