mirror of
https://github.com/denoland/deno.git
synced 2024-12-01 16:51:13 -05:00
feat(runtime): add stat and statSync methods to Deno.File (#10107)
This commit is contained in:
parent
5c2a8cdbdc
commit
da9219341f
4 changed files with 45 additions and 2 deletions
2
cli/dts/lib.deno.ns.d.ts
vendored
2
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -785,6 +785,8 @@ declare namespace Deno {
|
||||||
readSync(p: Uint8Array): number | null;
|
readSync(p: Uint8Array): number | null;
|
||||||
seek(offset: number, whence: SeekMode): Promise<number>;
|
seek(offset: number, whence: SeekMode): Promise<number>;
|
||||||
seekSync(offset: number, whence: SeekMode): number;
|
seekSync(offset: number, whence: SeekMode): number;
|
||||||
|
stat(): Promise<FileInfo>;
|
||||||
|
statSync(): FileInfo;
|
||||||
close(): void;
|
close(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,3 +103,35 @@ unitTest(function fileUsingNumberFileName(): void {
|
||||||
unitTest(function fileUsingEmptyStringFileName(): void {
|
unitTest(function fileUsingEmptyStringFileName(): void {
|
||||||
testSecondArgument("", "");
|
testSecondArgument("", "");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
unitTest({ perms: { read: true } }, function fileStatSyncSuccess(): void {
|
||||||
|
const file = Deno.openSync("README.md");
|
||||||
|
const fileInfo = file.statSync();
|
||||||
|
assert(fileInfo.isFile);
|
||||||
|
assert(!fileInfo.isSymlink);
|
||||||
|
assert(!fileInfo.isDirectory);
|
||||||
|
assert(fileInfo.size);
|
||||||
|
assert(fileInfo.atime);
|
||||||
|
assert(fileInfo.mtime);
|
||||||
|
// The `birthtime` field is not available on Linux before kernel version 4.11.
|
||||||
|
assert(fileInfo.birthtime || Deno.build.os === "linux");
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
unitTest({ perms: { read: true } }, async function fileStatSuccess(): Promise<
|
||||||
|
void
|
||||||
|
> {
|
||||||
|
const file = await Deno.open("README.md");
|
||||||
|
const fileInfo = await file.stat();
|
||||||
|
assert(fileInfo.isFile);
|
||||||
|
assert(!fileInfo.isSymlink);
|
||||||
|
assert(!fileInfo.isDirectory);
|
||||||
|
assert(fileInfo.size);
|
||||||
|
assert(fileInfo.atime);
|
||||||
|
assert(fileInfo.mtime);
|
||||||
|
// The `birthtime` field is not available on Linux before kernel version 4.11.
|
||||||
|
assert(fileInfo.birthtime || Deno.build.os === "linux");
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
});
|
||||||
|
|
|
@ -390,8 +390,6 @@
|
||||||
removeSync,
|
removeSync,
|
||||||
renameSync,
|
renameSync,
|
||||||
rename,
|
rename,
|
||||||
fstatSync,
|
|
||||||
fstat,
|
|
||||||
lstat,
|
lstat,
|
||||||
lstatSync,
|
lstatSync,
|
||||||
stat,
|
stat,
|
||||||
|
@ -403,6 +401,8 @@
|
||||||
umask,
|
umask,
|
||||||
link,
|
link,
|
||||||
linkSync,
|
linkSync,
|
||||||
|
fstatSync,
|
||||||
|
fstat,
|
||||||
futime,
|
futime,
|
||||||
futimeSync,
|
futimeSync,
|
||||||
utime,
|
utime,
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
((window) => {
|
((window) => {
|
||||||
const core = window.Deno.core;
|
const core = window.Deno.core;
|
||||||
const { read, readSync, write, writeSync } = window.__bootstrap.io;
|
const { read, readSync, write, writeSync } = window.__bootstrap.io;
|
||||||
|
const { fstat, fstatSync } = window.__bootstrap.fs;
|
||||||
const { pathFromURL } = window.__bootstrap.util;
|
const { pathFromURL } = window.__bootstrap.util;
|
||||||
|
|
||||||
function seekSync(
|
function seekSync(
|
||||||
|
@ -103,6 +104,14 @@
|
||||||
return seekSync(this.rid, offset, whence);
|
return seekSync(this.rid, offset, whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stat() {
|
||||||
|
return fstat(this.rid);
|
||||||
|
}
|
||||||
|
|
||||||
|
statSync() {
|
||||||
|
return fstatSync(this.rid);
|
||||||
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
core.close(this.rid);
|
core.close(this.rid);
|
||||||
}
|
}
|
Loading…
Reference in a new issue