isomorphic-git / lightning-fs

A lean and fast 'fs' for the browser
MIT License
487 stars 48 forks source link

add to change low level backend #91

Closed jcubic closed 2 years ago

jcubic commented 2 years ago

This is a replacement for #49

My test example:

class MemoryBackend {
  constructor() {
    this._store = new Map();
  }
  saveSuperblock(superblock) {
    this._store.set("!root", superblock)
  }
  loadSuperblock() {
    return this._store.get("!root")
  }
  readFile(inode) {
    return this._store.get(inode)
  }
  writeFile(inode, data) {
    return this._store.set(inode, data)
  }
  unlink(inode) {
    return this._store.delete(inode)
  }
  wipe() {
    this._store = new Map()
  }
  close() {

  }
}

var fs = new LightningFS("fs", { db: new MemoryBackend() });

(async () => {

    await fs.promises.writeFile('/foo', 'hello');
    const file = await fs.promises.readFile('/foo');
    console.log(file.toString());

})();
isomorphic-git-bot commented 2 years ago

:tada: This PR is included in version 4.5.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: