<commit_before>/**
# virtual file system -- service worker

This service worker provides a virtual file system at `/vfs/`

If you POST to /vfs/path/to/file it creates a virtual file at that url.
GET returns the file
DELETE removes it
GET /vsf/path/to/ returns the list of things in that virtual directory
GET /vsf/path/to/* returns the directory and its subdirectories
DELETE /vsf/path/to/ deletes the directory and its contents
If follows that:

GET /vsf/* returns the whole virtual tree.

## Note

Service workers *do not work on first page load*. Consequently, `vfs`
will *immediately* force a page reload if it sees that the controller is null.
It follows that if you want to use `vfs` you should load it as soon as 
possible to avoid rendering the user interface twice.
*/

export const vfs = (async () => {
  const {navigator} = window
  if (navigator.serviceWorker.controller === null) window.location.reload()
  if ('serviceWorker' in navigator) {
    return navigator.serviceWorker.register('/vfs.worker.js').then(registration => {
      // Registration was successful
      console.log('vfs service worker registration successful with scope: ' + registration.scope)
      return 'ok'
    }, err => {
      // registration failed :(
      throw new Error('ServiceWorker registration failed: ' + err)
    })<commit_msg>Update vfs.js<commit_after>/**
# virtual file system -- service worker

This service worker provides a virtual file system at `/vfs/`

If you POST to /vfs/path/to/file it creates a virtual file at that url.
GET returns the file
DELETE removes it
GET /vsf/path/to/ returns the list of things in that virtual directory
GET /vsf/path/to/* returns the directory and its subdirectories
DELETE /vsf/path/to/ deletes the directory and its contents
If follows that:

GET /vsf/* returns the whole virtual tree.

## Note

Service workers *do not work on first page load*. Consequently, `vfs`
will *immediately* force a page reload if it sees that the controller is null.
It follows that if you want to use `vfs` you should load it as soon as 
possible to avoid rendering the user interface twice.
*/

const serviceWorkerUrl = location.hostname === 'tonioloewald.github.io' ? '/bindinator.js/vfs.worker.js' : '/vfs.worker.js'

export const vfs = (async () => {
  const {navigator} = window
  if ('serviceWorker' in navigator) {
    return navigator.serviceWorker.register(serviceWorkerUrl).then(registration => {
      if (navigator.serviceWorker.controller === null) window.location.reload()
      // Registration was successful
      console.log('vfs service worker registration successful with scope: ' + registration.scope)
      return 'ok'
    }, err => {
      // registration failed :(
      throw new Error('ServiceWorker registration failed: ' + err)
    })
{'fraction_non_alphanumeric': 0.09378368666906216, 'fraction_numerical': 0.0, 'mean_word_length': 3.6711409395973154, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1573047', 'n_tokens_mistral': 769, 'n_tokens_neox': 753, 'n_words': 331}