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 🙏

© 2025 – Pkg Stats / Ryan Hefner

file-ts

v0.7.15

Published

A filesystem in your browser

Readme

file-ts

This is ZenFS, rebuilt to use tsc and modified slightly, essentially it's still ZenFS, but more modern build structure.

ZenFS is a file system that emulates the NodeJS filesystem API.

It works using a system of backends, which are used by ZenFS to store and retrieve data. ZenFS can also integrate with other tools.

ZenFS is a fork of BrowserFS.

Backends

ZenFS is modular and extensible. The core includes two built-in backends:

  • InMemory: Stores files in-memory. This is cleared when the runtime ends (e.g. a user navigating away from a web page or a Node process exiting)
  • Overlay: Use read-only file system as read-write by overlaying a writable file system on top of it. (copy-on-write)

ZenFS supports a number of other backends. Many are provided as separate packages under @zenfs. More backends can be defined by separate libraries by extending the FileSystem class and/or providing a Backend object.

For more information, see the docs.

Installing

npm install file-ts

Usage

[!NOTE] The examples are written in ESM.
If you are using CJS, you can require the package.
If using a browser environment without support for type=module in script tags, you can add a script tag to your HTML pointing to the browser.min.js and use ZenFS with the global ZenFS object.

import fs from 'file-ts'; // You can also use the named export, `fs`

fs.writeFileSync('/test.txt', 'Cool, I can do this in any JS environment (including browsers)!');

const contents = fs.readFileSync('/test.txt', 'utf-8');
console.log(contents);

Using different and/or multiple backends

A single InMemory backend is created by default, mounted on /.

You can configure ZenFS to use a different backend and mount multiple backends. It is strongly recommended to do so using the configure function.

You can use multiple backends by passing an object to configure which maps paths to file systems.

The following example mounts a zip file to /zip, in-memory storage to /tmp, and IndexedDB to /home. Note that / has the default in-memory backend.

import { configure, InMemory } from 'file-ts';
import { IndexedDB } from '@zenfs/dom';
import { Zip } from '@zenfs/zip';

const zipData = await (await fetch('mydata.zip')).arrayBuffer();

await configure({
	'/mnt/zip': { backend: Zip, zipData },
	'/tmp': InMemory,
	'/home': IndexedDB,
};

[!TIP] When configuring a mount point, you can pass in

  1. A Backend object, if the backend has no required options
  2. An object that has the options accepted by the backend and a backend property which is a Backend object
  3. A FileSystem instance (not recommended)

Here is an example that mounts the WebStorage backend from @zenfs/dom on /:

import { configure, fs } from 'file-ts';
import { WebStorage } from '@zenfs/dom';

await configure({ backend: WebStorage });

if (!fs.existsSync('/test.txt')) {
	fs.writeFileSync('/test.txt', 'This will persist across reloads!');
}

const contents = fs.readFileSync('/test.txt', 'utf-8');
console.log(contents);

FS Promises

The FS promises API is exposed as promises.

import { configure } from 'file-ts';
import { exists, writeFile } from 'file-ts/promises';
import { IndexedDB } from '@zenfs/dom';

await configure({ '/': IndexedDB });

const exists = await exists('/myfile.txt');
if (!exists) {
	await writeFile('/myfile.txt', 'Lots of persistant data');
}

[!NOTE] You can import the promises API using:

  1. Exports from file-ts/promises
  2. The promises export from file-ts
  3. fs.promises on the exported fs from file-ts.

Mounting and unmounting, creating backends

If you would like to create backends without configure (e.g. to do something dynamic at runtime), you may do so by importing the backend and calling resolveMountConfig with it.

You can then mount and unmount the backend instance by using mount and umount.

import { configure, resolveMountConfig, InMemory } from 'file-ts';
import { IndexedDB  } from '@zenfs/dom';
import { Zip } from '@zenfs/zip';

await configure({
	'/tmp': InMemory,
	'/home': IndexedDB,
};

fs.mkdirSync('/mnt');

const res = await fetch('mydata.zip');
const zipfs = await resolveMountConfig({ backend: Zip, zipData: await res.arrayBuffer() });
fs.mount('/mnt/zip', zipfs);

// do stuff with the mounted zip

fs.umount('/mnt/zip'); // finished using the zip

[!WARNING] Instances of backends follow the internal ZenFS API. You should never use a backend's methods unless you are extending a backend.

Using with bundlers

ZenFS exports a drop-in for Node's fs module (up to the version of @types/node in package.json), so you can use it for your bundler of preference using the default export.

Building

  • Make sure you have Node and NPM installed. You must have Node v18 or newer.
  • Install dependencies with npm install
  • Build using npm run build
  • You can find the built code in dist.

Testing

Run unit tests with npm test.