BrowserFS icon indicating copy to clipboard operation
BrowserFS copied to clipboard

Initialize BrowserFS with a file system

Open mjohngladson opened this issue 3 years ago • 1 comments

I get the below error in my react app while trying to write to text file

"Initialize BrowserFS with a file system using BrowserFS.initialize(filesystem)"

after analysing found the root was null.

Can someone please help how to set the root/ how to initialize?

mjohngladson avatar Nov 20 '20 19:11 mjohngladson

Please have a look at the Readme.md it explains how to initialize a filesystem.

NexusNull avatar Nov 27 '20 09:11 NexusNull

readme does not explain BrowserFS.initialize

some examples

BrowserFS.initialize(new BrowserFS.FileSystem.InMemory());

callbacks http://jvilk.com/browserfs/1.4.1/#advanced-usage

BrowserFS.FileSystem.LocalStorage.Create(function(e, lsfs) {
  BrowserFS.FileSystem.InMemory.Create(function(e, inMemory) {
    BrowserFS.FileSystem.IndexedDB.Create({}, function(e, idbfs) {
      BrowserFS.FileSystem.MountableFileSystem.Create({
        '/tmp': inMemory,
        '/home': idbfs,
        '/mnt/usb0': lsfs
      }, function(e, mfs) {
        BrowserFS.initialize(mfs);
        // BFS is now ready to use!
      });
    });
  });
});

async await, example from https://github.com/milahu/browsix

import { onMount, createSignal, Show } from "solid-js";
import pify from "pify";
import * as BrowserFS from "browserfs";
import {BootWith} from "../src/kernel/kernel"
import {Terminal} from "./elements/browsix-terminal/browsix-terminal"

export default function App() {
  const [getKernel, setKernel] = createSignal();
  onMount(async () => {
    const rootFs = await pify(BrowserFS.FileSystem.MountableFileSystem.Create)({
      '/tmp': await pify(BrowserFS.FileSystem.InMemory.Create)({}),
      '/home': await pify(BrowserFS.FileSystem.IndexedDB.Create)({}),
    })
    BrowserFS.initialize(rootFs);
    BootWith(rootFs, setKernel);
  });
  return (
    <Show when={getKernel()} fallback={<div>Loading kernel ...</div>}>
      <Terminal kernel={getKernel()}/>
    </Show>
  )
}

duplicate https://github.com/jvilk/BrowserFS/issues/210

milahu avatar Dec 10 '22 14:12 milahu

@mjohngladson See http://jvilk.com/browserfs/2.0.0-beta/modules/core_browserfs.html#initialize

james-pre avatar Mar 09 '23 23:03 james-pre