mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -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;
|
||||
seek(offset: number, whence: SeekMode): Promise<number>;
|
||||
seekSync(offset: number, whence: SeekMode): number;
|
||||
stat(): Promise<FileInfo>;
|
||||
statSync(): FileInfo;
|
||||
close(): void;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,3 +103,35 @@ unitTest(function fileUsingNumberFileName(): void {
|
|||
unitTest(function fileUsingEmptyStringFileName(): void {
|
||||
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,
|
||||
renameSync,
|
||||
rename,
|
||||
fstatSync,
|
||||
fstat,
|
||||
lstat,
|
||||
lstatSync,
|
||||
stat,
|
||||
|
@ -403,6 +401,8 @@
|
|||
umask,
|
||||
link,
|
||||
linkSync,
|
||||
fstatSync,
|
||||
fstat,
|
||||
futime,
|
||||
futimeSync,
|
||||
utime,
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
((window) => {
|
||||
const core = window.Deno.core;
|
||||
const { read, readSync, write, writeSync } = window.__bootstrap.io;
|
||||
const { fstat, fstatSync } = window.__bootstrap.fs;
|
||||
const { pathFromURL } = window.__bootstrap.util;
|
||||
|
||||
function seekSync(
|
||||
|
@ -103,6 +104,14 @@
|
|||
return seekSync(this.rid, offset, whence);
|
||||
}
|
||||
|
||||
stat() {
|
||||
return fstat(this.rid);
|
||||
}
|
||||
|
||||
statSync() {
|
||||
return fstatSync(this.rid);
|
||||
}
|
||||
|
||||
close() {
|
||||
core.close(this.rid);
|
||||
}
|
Loading…
Reference in a new issue