Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vol.toJSON() does not contain stats of a file #562

Open
marco-a opened this issue Aug 8, 2020 · 2 comments
Open

vol.toJSON() does not contain stats of a file #562

marco-a opened this issue Aug 8, 2020 · 2 comments

Comments

@marco-a
Copy link

marco-a commented Aug 8, 2020

First of all, great library!

I wanted to use it for unit testing a part of my application.

Sadly it seems like vol.toJSON() does not export file stats (such as uid, gid etc.).

I had a quick glance over the source code and it looks like these are returned somewhere:

memfs/src/node.ts

Lines 214 to 229 in 6842252

toJSON() {
return {
ino: this.ino,
uid: this.uid,
gid: this.gid,
atime: this.atime.getTime(),
mtime: this.mtime.getTime(),
ctime: this.ctime.getTime(),
perm: this.perm,
mode: this.mode,
nlink: this.nlink,
symlink: this.symlink,
data: this.getString(),
};
}
}

const vol = memfs.Volume.fromJSON({ '/foo': 'bar' });
vol.readFileSync('/foo'); // bar
vol.chownSync("/foo", 200, 200)
// logs 200 as expected
console.log(vol.statSync("/foo").uid)
// does not export set uid & gid
console.log(vol.toJSON())

Is this intentional ?

@G-Rath
Copy link
Collaborator

G-Rath commented Mar 31, 2021

Yes, because toJSON is meant to be the opposite of fromJSON, which doesn't support setting stats of a file.

@takase1121
Copy link

Is it possible to make it export the stat alongside the content? This'll allow users to preserve the entire filesystem (including metadata) in localStorage or maybe IndexedDB without messing up the mtimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants