feat: URL support in Deno filesystem methods (#5990)

This commit is contained in:
River 2020-06-12 02:36:20 +10:00 committed by GitHub
parent 813210d433
commit 818a801092
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 741 additions and 66 deletions

View file

@ -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,