npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@webufs/webufs

v0.1.2

Published

webufs: a Linux-style web filesystem framework

Downloads

5

Readme

Webufs, a Linux-style Web Filesystem Framework.

If you want to use this library directly in your browser, please see the document of the package "@webufs/webufs-browser"

I just started to work on this library. The current versions are all unstable. I will also improve its performance in the future. Please wait and see.

If you have any issues or suggestions, feel free to discuss them on GitHub. Thanks!

Usage

The createDefaultContext method will mount the default in-memory filesystem at / (data will be lost upon closing).

To mount other filesystems, see section Mounting Other FS below.

Basic Directory Operation:

import { createDefaultContext } from '@webufs/webufs'

// Yes, it's async
const ctx = await createDefaultContext()

await ctx.mkdir('a')
await ctx.chdir('/a')
console.log(ctx.getcwd())       /* '/a' */
await ctx.chdir('..')
await ctx.rmdir('./a/')
// ...

// scan directory
fd = await ctx.open('/', { directory: true })
let fileInfos = await fd.getdents()
for (let dirEntry of fileInfos) {
    console.log(`name: ${dirEntry.name}, type: ${dirEntry.type} `)
}

// check if file exists
const status = await ctx.access('abc.png')
if (status) {
    console.error('File abc.png doesn\'t exist. ')
}
// ...

Basic File Operation:

const fd = await ctx.open('a.txt', { create: true })

const src = new Uint8Array([0x30, 0x31, 0x32, 0x33])
await fd.write(src.buffer)
await fd.write(src.buffer)
await fd.write(src.buffer)

const dst = new ArrayBuffer(8)
const dstView = new DataView(dst)
await fd.seek(2, SeekType.SET)          // offset +2 relative to file start 
// You can seek relative to SET, CUR or END.
await fd.read(dst)
// read data from file into dstView...
// NOTE: read(size) will return the number of bytes that are actually read, ranging in the interval [0, size], and
// when less than size, it means that we are near the end of the file.

//  don't forget to close the file (this will also flush pending writing and release reference)
await fd.close()

// delete a file
await ctx.unlink('a.txt')

Read file till the end:

fd = await ctx.open('a.txt', { readonly: true })
let size = 0
const buffer = new ArrayBuffer(0x100)
while (true) {
    const cnt = await fd.read(bufer)
    size += cnt
    if (cnt < 0x100) break
}
await fd.close()

console.log(`File Size = ${size}`)

Discard original content (with size set back to zero) and re-write:

fd = await ctx.open('a.txt', { trunc: true })
const src = new Uint8Array([0x30, 0x31, 0x32, 0x33])
await fd.write(src.buffer)
await fd.close()

Mounting Other FS

We take @webufs/webufs-idb, a filesystem implementation of IndexedDB backend, for example:

import { createDefaultContext } from '@webufs/webufs'
import { IDBFS } from '@webufs/webufs-idb'

const ctx = await createDefaultContext()
ctx.getVFS().registerFSType(IDBFS)
await ctx.mkdir('idb')
await ctx.mount('idbfs', '/idb')
await ctx.chdir('idb')

// See the documentation of '@webufs/webufs-idb' for further detail.

FS umounting not implemented yet.

About Versioning

Change of major version number will introduce incompatibility to both users and FS backend and plugin developers.

Change of minor version number keeps compatibility to users, but may cause API incompatibility to the backend and plugin developers.

Change of patch version number keeps compatibility to both users and developers.

Hope (not implemented yet)

We might also add shell-like support:

await sh.cd('/home/user/').run()
await sh.echo('Hello!').pipe(base64()).to('a.txt').run()
await sh.cmd(find('./src', '-name', '*.ts'))
    .pipe(xargs(cat()))
    .pipe(wc('-l'))
    .run()
/**
 * base64, find, cat are util functions using our VFS API.
 */

That would be cool.

Some Ideas

I found that we can generate a URL from Blob and use it to spawn Web Workers. That might give some ideas...