jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.06k stars 215 forks source link

Expose fs.Stats constructor #232

Closed billiegoose closed 5 years ago

billiegoose commented 6 years ago

I need to transport some fs.Stats objects across JS domains, by serializing them and deserializing them. I see there is a nifty .toBuffer() instance method and a .fromBuffer() static method to do this! But I don't see how to get ahold of the static method. The Stats constructor isn't exposed? In Node, I can do this:

> let s = new (require('fs').Stats)
undefined
> s
Stats {
  dev: undefined,
  mode: undefined,
  nlink: undefined,
  uid: undefined,
  gid: undefined,
  rdev: undefined,
  blksize: undefined,
  ino: undefined,
  size: undefined,
  blocks: undefined,
  atimeMs: undefined,
  mtimeMs: undefined,
  ctimeMs: undefined,
  birthtimeMs: undefined,
  atime: Invalid Date,
  mtime: Invalid Date,
  ctime: Invalid Date,
  birthtime: Invalid Date }

Could you add Stats as a public static member of fs (to match the Node API)?

jvilk commented 6 years ago

Ah, this is an oversight. It's exposed on the FS class, but not on the node_fs singleton.

A simple fix is to expose it on that singleton _fsMock object in node_fs.