Skip to content

Commit

Permalink
feat(runtime): add stat and statSync methods to Deno.File
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervonb committed Apr 10, 2021
1 parent a87da4b commit a329df4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions cli/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
19 changes: 19 additions & 0 deletions runtime/js/30_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@
});
}

function fstatSync(rid) {
return parseFileInfo(core.jsonOpSync("op_fstat_sync", rid));
}

async function fstat(rid) {
return parseFileInfo(await core.jsonOpAsync("op_fstat_async", rid));
}


class File {
#rid = 0;

Expand Down Expand Up @@ -103,6 +112,14 @@
return seekSync(this.rid, offset, whence);
}

stat() {
return fstat(this.rid);
}

statSync() {
return this.fstatSync(this.rid);
}

close() {
core.close(this.rid);
}
Expand Down Expand Up @@ -206,5 +223,7 @@
openSync,
seek,
seekSync,
fstatSync,
fstat,
};
})(this);
10 changes: 0 additions & 10 deletions runtime/js/30_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,6 @@
};
}

function fstatSync(rid) {
return parseFileInfo(core.jsonOpSync("op_fstat_sync", rid));
}

async function fstat(rid) {
return parseFileInfo(await core.jsonOpAsync("op_fstat_async", rid));
}

async function lstat(path) {
const res = await core.jsonOpAsync("op_stat_async", {
path: pathFromURL(path),
Expand Down Expand Up @@ -390,8 +382,6 @@
removeSync,
renameSync,
rename,
fstatSync,
fstat,
lstat,
lstatSync,
stat,
Expand Down
4 changes: 2 additions & 2 deletions runtime/js/90_deno_ns.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
listenDatagram: __bootstrap.netUnstable.listenDatagram,
startHttp: __bootstrap.http.startHttp,
startTls: __bootstrap.tls.startTls,
fstatSync: __bootstrap.fs.fstatSync,
fstat: __bootstrap.fs.fstat,
fstatSync: __bootstrap.files.fstatSync,
fstat: __bootstrap.files.fstat,
ftruncateSync: __bootstrap.fs.ftruncateSync,
ftruncate: __bootstrap.fs.ftruncate,
umask: __bootstrap.fs.umask,
Expand Down

0 comments on commit a329df4

Please sign in to comment.