Skip to content

muze-nl/jsfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub License GitHub package.json version NPM Version npm bundle size Project stage: Experimental

JSFS: a light-weight javascript filesystem abstraction

import '@muze-nl/jsfs'

const client = jsfs.fs(
	new jsfs.adapters.https('https://example.org/')
)

Table of Contents

  1. Introduction
  2. Usage
  3. Adapters
  4. Contributing
  5. License

Introduction

JSFS is a light-weight filesystem abstraction for javascript, inspired by PHP's Flysystem. Unlike other solutions, like ZenFS, it has a minimal API. Just these functions:

  • cd
  • read
  • write
  • delete
  • exists
  • list

There is no support for streaming reads or writes yet.

Usage

npm install @muze-nl/jsfs

In the browser, using a cdn:

<script src="https://cdn.jsdelivr.net/npm/@muze-nl/jsfs/dist/browser.js"></script>

Using ES6 modules, in the browser or Node (or Deno, or...):

import '@muze-nl/jsfs'

const client = jsfs.fs(new jsfs.adapters.https('https://example.org/'))

Adapters

Using Adapters, you can connect any filesystem-like API. By default JSFS comes with an HttpAdapter, that fetches HTML pages and parses them to extract filesystem data. Any site that is compatible with Apaches default directory listing will work. Calling write() results in a PUT request to the given path. Similarly delete() will send a DELETE request. exists() will send a HEAD request.

In a separate package, you can get an Adapter written for Solid PODs (see https://solidproject.org/). Check out @muze-nl/jsfs-solid for more information.

To write a new Adapter, you must implement this interface:

{
	get name()
	get path()
	supportsWrite()
	cd(path)
	async write(path, contents, metadata=null)
	async read(path)
	async exists(path)
	async delete(path)
	async list(path)
}

The list method must return an array of objects with at least these properties:

{
	filename,
	path,
	name
}

The read method must return an object with at least these properties:

{
	type,
	name,
	contents,
}

License

This software is licensed under MIT open source license. See the License file.

About

javascript filesystem abstraction, inspired by php's flysystem

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors