Skip to content

Add fs option to allow passing virtual filesystem#430

Closed
mmkal wants to merge 2 commits intoisaacs:masterfrom
mmkal:fs-option
Closed

Add fs option to allow passing virtual filesystem#430
mmkal wants to merge 2 commits intoisaacs:masterfrom
mmkal:fs-option

Conversation

@mmkal
Copy link
Copy Markdown
Contributor

@mmkal mmkal commented Nov 18, 2020

Fixes #429


This enables passing in a virtual filesystem compatible with the fs module. There are several matching the fs API:

Example:

let glob = require('glob')
let memfs = require('memfs')

let volume = memfs.Volume.fromJSON({
  '/foo/bar/abc.txt': 'abc',
  '/foo/bar/def.log': 'def',
  '/foo/bar/xyz.txt': 'xyz',
})

glob.sync('/foo/bar/*.txt', { fs: volume }) // returns ['/foo/bar/abc.txt', '/foo/bar/xyz.txt']

Allows usage of glob in lots more places without requiring users to monkey-patch. With this change, glob could be used in the browser, with dropbox, S3, purely in memory like above (useful for testing) and many others.


After writing that issue up, I had a look at the code and the change required is very small so I thought I'd just open a PR.

@isaacs isaacs closed this in df4598a Sep 22, 2021
@isaacs
Copy link
Copy Markdown
Owner

isaacs commented Sep 23, 2021

Thanks, landed and published as 7.2.0

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

Successfully merging this pull request may close these issues.

Virtual file system option?

2 participants