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

Configurable fs #1835

Closed
bajrangCoder opened this issue Oct 24, 2023 · 10 comments
Closed

Configurable fs #1835

bajrangCoder opened this issue Oct 24, 2023 · 10 comments

Comments

@bajrangCoder
Copy link

Is there any way to configure any type of fs client to isomorphic-git?

As in my case I have to use cordova-plugin-file for fs stuffs but isomorphic-git only supports nodejs like fs only(i guess)

I have to integrate isomorphic-git for git client in this app and here is it's fs which uses cordova file , sdcard plugin etc.

Any solution will be appreciated 🤗

@jcubic
Copy link
Contributor

jcubic commented Oct 24, 2023

I think the easiest way is to look at lightningFS library that implements fs module that can be used in web browser.
But to have custom fs you need to implement custom backend.

@bajrangCoder
Copy link
Author

Ok Thanks for your response!
Can I get some hints or any sample of implementing custom backed? As on lightningFS library only mention about backend but there is no any docs or example about it

@jcubic
Copy link
Contributor

jcubic commented Oct 25, 2023

There is information in README: Providing a custom backend (advanced usage). The sad thing is that the custom backend is almost like an entirely new implementation of fs.

I've added a way to swap Key/Value pair (db option) in lightning-fs, and was always wondering what is the point of custom backend if it's like your own lightning-fs library.

@bajrangCoder
Copy link
Author

I have seen it but how I will pass my custom IBackend as it mentioned in readme that I will need to pass on option backend option but there is no any backend option in option interface

The sad thing is that the custom backend is almost like an entirely new implementation of fs.

Yes it's totally like having a own fs

@jcubic
Copy link
Contributor

jcubic commented Oct 26, 2023

It seems there is an option backend:

https://github.com/isomorphic-git/lightning-fs/blob/main/src/PromisifiedFS.js#L82C29-L82C36

But it's not in TypeScript definition. If you don't use TypeScript you can try it. And if you use TypeScript maybe you will need to put as any somewhere.

@bajrangCoder
Copy link
Author

Yeah there are some issues in lightning fs typings declaration file as it makes db option required. For now I have modified it and tested fs.promises.readdir()and it's worked after doing some bypassings.

And I want to ask that how can I overide the default function that disturb the filepath as in my case when I pass these type of paths : content://com.externalstorage....../ then lighting fs convert this path to this : ./content:/com......
As it will be needed in any case for my use case it's not required

Also noticed one error that occurs when ever I start my app but it doesn't the affect any thing , here is the screenshot of error:

Screenshot_20231026-153617~2

Note
I initialise the lighting fs in constructor like this 👇

constructor() {
  const customBackend = new FsBackend();
  this.fs = new FS();
  this.fs.promises.init("myfs", { backend: customBackend });
}

@jcubic
Copy link
Contributor

jcubic commented Oct 26, 2023

Don't call the init function it's an internal method.

@bajrangCoder
Copy link
Author

bajrangCoder commented Oct 26, 2023

Ok but what about this one 👇

And I want to ask that how can I overide the default function that disturb the filepath as in my case when I pass these type of paths : content://com.externalstorage....../ then lighting fs convert this path to this : ./content:/com......
As it will be needed in any case for my use case it's not required

Edit: I have used like this but still same error:

this.fs = new FS("myfs", { backend: customBackend });

@jcubic
Copy link
Contributor

jcubic commented Oct 26, 2023

I think that it will be much simpler to just implement your own fs and all the methods that are required. But if you would like to use lightning-fs you will need to fork it and modify to not normalize the path (or whatever function it used for paths).

@bajrangCoder
Copy link
Author

Ok

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