summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/fs/30_fs.js53
1 files changed, 34 insertions, 19 deletions
diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js
index 72123f630..a8ae7ad3a 100644
--- a/ext/fs/30_fs.js
+++ b/ext/fs/30_fs.js
@@ -211,16 +211,30 @@ async function rename(oldpath, newpath) {
// 3. u64
// offset += 2
// high u32 | low u32
+//
+// 4. ?u64 converts a zero u64 value to JS null on Windows.
function createByteStruct(types) {
// types can be "date", "bool" or "u64".
let offset = 0;
- let str = "return {";
+ let str =
+ 'const unix = Deno.build.os === "darwin" || Deno.build.os === "linux"; return {';
const typeEntries = ObjectEntries(types);
for (let i = 0; i < typeEntries.length; ++i) {
- const { 0: name, 1: type } = typeEntries[i];
+ let { 0: name, 1: type } = typeEntries[i];
+
+ const optional = type.startsWith("?");
+ if (optional) type = type.slice(1);
if (type == "u64") {
- str += `${name}: view[${offset}] + view[${offset + 1}] * 2**32,`;
+ if (!optional) {
+ str += `${name}: view[${offset}] + view[${offset + 1}] * 2**32,`;
+ } else {
+ str += `${name}: (unix ? (view[${offset}] + view[${
+ offset + 1
+ }] * 2**32) : (view[${offset}] + view[${
+ offset + 1
+ }] * 2**32) || null),`;
+ }
} else if (type == "date") {
str += `${name}: view[${offset}] === 0 ? null : new Date(view[${
offset + 2
@@ -245,17 +259,18 @@ const { 0: statStruct, 1: statBuf } = createByteStruct({
atime: "date",
birthtime: "date",
dev: "u64",
- ino: "u64",
- mode: "u64",
- nlink: "u64",
- uid: "u64",
- gid: "u64",
- rdev: "u64",
- blksize: "u64",
- blocks: "u64",
+ ino: "?u64",
+ mode: "?u64",
+ nlink: "?u64",
+ uid: "?u64",
+ gid: "?u64",
+ rdev: "?u64",
+ blksize: "?u64",
+ blocks: "?u64",
});
function parseFileInfo(response) {
+ const unix = core.build.os === "darwin" || core.build.os === "linux";
return {
isFile: response.isFile,
isDirectory: response.isDirectory,
@@ -267,14 +282,14 @@ function parseFileInfo(response) {
? new Date(response.birthtime)
: null,
dev: response.dev,
- ino: response.ino,
- mode: response.mode,
- nlink: response.nlink,
- uid: response.uid,
- gid: response.gid,
- rdev: response.rdev,
- blksize: response.blksize,
- blocks: response.blocks,
+ ino: unix ? response.ino : null,
+ mode: unix ? response.mode : null,
+ nlink: unix ? response.nlink : null,
+ uid: unix ? response.uid : null,
+ gid: unix ? response.gid : null,
+ rdev: unix ? response.rdev : null,
+ blksize: unix ? response.blksize : null,
+ blocks: unix ? response.blocks : null,
};
}