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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: unionFS.promises.use() #751

Open
ajvincent opened this issue Jan 4, 2023 · 3 comments
Open

Suggestion: unionFS.promises.use() #751

ajvincent opened this issue Jan 4, 2023 · 3 comments

Comments

@ajvincent
Copy link

ajvincent commented Jan 4, 2023

I don't always use fs, but when I do, I prefer fs/promises. 馃槃

import fs from "fs";
import { Union } from "unionfs";
import { IFS } from "unionfs/lib/fs";

type FS_Promises = (typeof fs)["promises"];

type UseFSPromises = FS_Promises & {
  use(filesystem: FS_Promises): UseFSPromises
};

export function UnionFSPromises() : UseFSPromises
{
  const unionFS = new Union;
  const promises = unionFS.promises as UseFSPromises;
  promises.use = function(filesystem: FS_Promises) : UseFSPromises {
    unionFS.use({ promises: filesystem } as IFS);
    return this;
  }

  return promises;
}
@G-Rath
Copy link
Collaborator

G-Rath commented Jan 4, 2023

I'm not sure what you're suggesting here - afaik unionfs should already work with fs.promises; could you explain in more detail what you're experiencing, and what you think could be improved?

@ajvincent
Copy link
Author

Okay, you're looking for a genuine use case. Yes, unionfs works with fs.promises, at least as far as I can see. (Forgive me for filing right away, as I'm a first-time user of this library.)

Whenever possible, I prefer to use await statements and async functions. I usually import fs/promises instead of fs.

I was reading npmjs's package pages for unionfs and memfs, and thinking, "wow, this is really nice, and simple." Union instances have a .use() method for adding typeof fs instances.

My ideal case would be something like this:

import fs from "fs/promises";
import { Union } from "unionfs/promises";
import { Volume, createFSFromVolume } from "memfs/promises";

export function TemporaryFSPromises() : Union {
  const vol = new Volume;
  const inMemoryFS = createFsFromVolume(vol);

  const unionFS = new Union;
  return unionFS.use(fs).use(inMemoryFS);
}

In other words, like the synchronous filesystem API of Union.prototype.use, I'm looking for an asynchronous filesystem API for Union.prototype.promise.use or UnionPromise.prototype.use (assuming the latter would exist as a spin-off into its own export or package).

As my code sample in the original post suggests, I've already figured out how to emulate this on my own, so it's not a strict need. I just think, for parity with the fs/promises NodeJS package, it would be nice to have.

@G-Rath
Copy link
Collaborator

G-Rath commented Jan 4, 2023

Right, so you're asking for a /promises aliases - I'm not against exploring that, though I don't know if it'll actually be worth it since fs/promises is literally an alias of fs.promises that's exported directly which we already support, and it might require some complexity to maintain two different versions of the Union class? (which probably should actually be the same class 馃)

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

2 participants