summaryrefslogtreecommitdiff
path: root/cli/js/ops/fs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/ops/fs')
-rw-r--r--cli/js/ops/fs/chmod.ts7
-rw-r--r--cli/js/ops/fs/chown.ts7
-rw-r--r--cli/js/ops/fs/copy_file.ts16
-rw-r--r--cli/js/ops/fs/open.ts10
-rw-r--r--cli/js/ops/fs/read_dir.ts7
-rw-r--r--cli/js/ops/fs/remove.ts10
-rw-r--r--cli/js/ops/fs/stat.ts13
7 files changed, 53 insertions, 17 deletions
diff --git a/cli/js/ops/fs/chmod.ts b/cli/js/ops/fs/chmod.ts
index 91e898360..76a3c8f49 100644
--- a/cli/js/ops/fs/chmod.ts
+++ b/cli/js/ops/fs/chmod.ts
@@ -1,10 +1,13 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
+import { pathFromURL } from "../../util.ts";
-export function chmodSync(path: string, mode: number): void {
+export function chmodSync(path: string | URL, mode: number): void {
+ path = pathFromURL(path);
sendSync("op_chmod", { path, mode });
}
-export async function chmod(path: string, mode: number): Promise<void> {
+export async function chmod(path: string | URL, mode: number): Promise<void> {
+ path = pathFromURL(path);
await sendAsync("op_chmod", { path, mode });
}
diff --git a/cli/js/ops/fs/chown.ts b/cli/js/ops/fs/chown.ts
index d6e3702c6..f24ab5e55 100644
--- a/cli/js/ops/fs/chown.ts
+++ b/cli/js/ops/fs/chown.ts
@@ -1,14 +1,17 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
+import { pathFromURL } from "../../util.ts";
-export function chownSync(path: string, uid: number, gid: number): void {
+export function chownSync(path: string | URL, uid: number, gid: number): void {
+ path = pathFromURL(path);
sendSync("op_chown", { path, uid, gid });
}
export async function chown(
- path: string,
+ path: string | URL,
uid: number,
gid: number
): Promise<void> {
+ path = pathFromURL(path);
await sendAsync("op_chown", { path, uid, gid });
}
diff --git a/cli/js/ops/fs/copy_file.ts b/cli/js/ops/fs/copy_file.ts
index 4c8c74667..6bbb3f599 100644
--- a/cli/js/ops/fs/copy_file.ts
+++ b/cli/js/ops/fs/copy_file.ts
@@ -1,13 +1,23 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
+import { pathFromURL } from "../../util.ts";
+
+export function copyFileSync(
+ fromPath: string | URL,
+ toPath: string | URL
+): void {
+ fromPath = pathFromURL(fromPath);
+ toPath = pathFromURL(toPath);
-export function copyFileSync(fromPath: string, toPath: string): void {
sendSync("op_copy_file", { from: fromPath, to: toPath });
}
export async function copyFile(
- fromPath: string,
- toPath: string
+ fromPath: string | URL,
+ toPath: string | URL
): Promise<void> {
+ fromPath = pathFromURL(fromPath);
+ toPath = pathFromURL(toPath);
+
await sendAsync("op_copy_file", { from: fromPath, to: toPath });
}
diff --git a/cli/js/ops/fs/open.ts b/cli/js/ops/fs/open.ts
index afe713db8..3742d0b52 100644
--- a/cli/js/ops/fs/open.ts
+++ b/cli/js/ops/fs/open.ts
@@ -1,5 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
+import { pathFromURL } from "../../util.ts";
export interface OpenOptions {
read?: boolean;
@@ -15,13 +16,18 @@ export interface OpenOptions {
mode?: number;
}
-export function openSync(path: string, options: OpenOptions): number {
+export function openSync(path: string | URL, options: OpenOptions): number {
const mode: number | undefined = options?.mode;
+ path = pathFromURL(path);
return sendSync("op_open", { path, options, mode });
}
-export function open(path: string, options: OpenOptions): Promise<number> {
+export function open(
+ path: string | URL,
+ options: OpenOptions
+): Promise<number> {
const mode: number | undefined = options?.mode;
+ path = pathFromURL(path);
return sendAsync("op_open", {
path,
options,
diff --git a/cli/js/ops/fs/read_dir.ts b/cli/js/ops/fs/read_dir.ts
index 1e8d79edc..09c5d1c12 100644
--- a/cli/js/ops/fs/read_dir.ts
+++ b/cli/js/ops/fs/read_dir.ts
@@ -1,5 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
+import { pathFromURL } from "../../util.ts";
export interface DirEntry {
name: string;
@@ -16,11 +17,13 @@ function res(response: ReadDirResponse): DirEntry[] {
return response.entries;
}
-export function readDirSync(path: string): Iterable<DirEntry> {
+export function readDirSync(path: string | URL): Iterable<DirEntry> {
+ path = pathFromURL(path);
return res(sendSync("op_read_dir", { path }))[Symbol.iterator]();
}
-export function readDir(path: string): AsyncIterable<DirEntry> {
+export function readDir(path: string | URL): AsyncIterable<DirEntry> {
+ path = pathFromURL(path);
const array = sendAsync("op_read_dir", { path }).then(res);
return {
async *[Symbol.asyncIterator](): AsyncIterableIterator<DirEntry> {
diff --git a/cli/js/ops/fs/remove.ts b/cli/js/ops/fs/remove.ts
index d5af82f9b..d1a8702f1 100644
--- a/cli/js/ops/fs/remove.ts
+++ b/cli/js/ops/fs/remove.ts
@@ -1,17 +1,23 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
+import { pathFromURL } from "../../util.ts";
export interface RemoveOptions {
recursive?: boolean;
}
-export function removeSync(path: string, options: RemoveOptions = {}): void {
+export function removeSync(
+ path: string | URL,
+ options: RemoveOptions = {}
+): void {
+ path = pathFromURL(path);
sendSync("op_remove", { path, recursive: !!options.recursive });
}
export async function remove(
- path: string,
+ path: string | URL,
options: RemoveOptions = {}
): Promise<void> {
+ path = pathFromURL(path);
await sendAsync("op_remove", { path, recursive: !!options.recursive });
}
diff --git a/cli/js/ops/fs/stat.ts b/cli/js/ops/fs/stat.ts
index e8fd28218..93d31fc3f 100644
--- a/cli/js/ops/fs/stat.ts
+++ b/cli/js/ops/fs/stat.ts
@@ -1,6 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
import { build } from "../../build.ts";
+import { pathFromURL } from "../../util.ts";
export interface FileInfo {
size: number;
@@ -65,7 +66,8 @@ export function parseFileInfo(response: StatResponse): FileInfo {
};
}
-export async function lstat(path: string): Promise<FileInfo> {
+export async function lstat(path: string | URL): Promise<FileInfo> {
+ path = pathFromURL(path);
const res = (await sendAsync("op_stat", {
path,
lstat: true,
@@ -73,7 +75,8 @@ export async function lstat(path: string): Promise<FileInfo> {
return parseFileInfo(res);
}
-export function lstatSync(path: string): FileInfo {
+export function lstatSync(path: string | URL): FileInfo {
+ path = pathFromURL(path);
const res = sendSync("op_stat", {
path,
lstat: true,
@@ -81,7 +84,8 @@ export function lstatSync(path: string): FileInfo {
return parseFileInfo(res);
}
-export async function stat(path: string): Promise<FileInfo> {
+export async function stat(path: string | URL): Promise<FileInfo> {
+ path = pathFromURL(path);
const res = (await sendAsync("op_stat", {
path,
lstat: false,
@@ -89,7 +93,8 @@ export async function stat(path: string): Promise<FileInfo> {
return parseFileInfo(res);
}
-export function statSync(path: string): FileInfo {
+export function statSync(path: string | URL): FileInfo {
+ path = pathFromURL(path);
const res = sendSync("op_stat", {
path,
lstat: false,