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

idb-filesystem-api

v0.0.1

Published

## 简介 基于indexedDB遵循 [File System API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API) 异步 API 实现的前端文件系统。

Readme

基于indexedDB和promise的文件系统

简介

基于indexedDB遵循 File System API 异步 API 实现的前端文件系统。

特点

  • 非安全上下文也可用
  • 支持多实例
  • 良好的数据可观测行

API

如何使用


async function init() {

  // 获取所有实例
  const allSystems = await getAllIDBFileSystem();
  console.log("allSystems:", allSystems);

  const rootDir = await getInstance();
  const dirHandle = await rootDir.getDirectoryHandle("测试文件夹1", { create: true });
  const dirHandleL2 = await dirHandle.getDirectoryHandle("测试文件夹1的子文件夹1", {
    create: true,
  });
  const dirHandleL2_2 = await dirHandle.getDirectoryHandle("测试文件夹1的子文件夹2", {
    create: true,
  });

  const fileHandle = await rootDir.getFileHandle("测试文件1.txt", { create: true });

  const fileHandleL2_1 = await dirHandleL2.getFileHandle(
    "测试文件夹1的子文件夹1的文件.txt",
    {
      create: true,
    }
  );
  const fileHandleL2_2 = await dirHandleL2.getFileHandle(
    "测试文件夹1的子文件夹1的文件2.txt",
    { create: true }
  );

  // resolve
  dirHandle
    .resolve(fileHandle)
    .then((r) => console.log("resolve:", r))
    .catch(console.error);
  dirHandle
    .resolve(dirHandle)
    .then((r) => console.log("resolve:", r))
    .catch(console.error);
  dirHandleL2_2
    .resolve(dirHandle)
    .then((r) => console.log("resolve:", r))
    .catch(console.error);

  // 遍历
  const tempDir = dirHandle;
  for await (const [key, value] of tempDir.entries()) {
    console.log({ key, value });
  }
  for await (const key of tempDir.keys()) {
    console.log("key:", key);
  }
  for await (const v of tempDir.values()) {
    console.log("v:", v);
  }

  // isSameEntry
  fileHandle
    .isSameEntry(fileHandleL2_2)
    .then((r) => console.log("fileHandle.isSameEntry(fileHandleL2_2):", r));
  fileHandle
    .isSameEntry(fileHandle)
    .then((r) => console.log("fileHandle.isSameEntry(fileHandle):", r));

  rootDir
    .isSameEntry(dirHandle)
    .then((r) => console.log("rootDir.isSameEntry(dirHandle):", r));
  dirHandle
    .isSameEntry(dirHandle)
    .then((r) => console.log("dirHandle.isSameEntry(dirHandle):", r));

  // createWritable
  const contents =
    "我们都是好孩子我们都是好孩子我们都是好孩子我们都是好孩子我们都是好孩子我们都是好孩子我们都是好孩子我们都是好孩子";
  const writable = await fileHandleL2_1.createWritable();
  // Write the contents of the file to the stream.
  await writable.write(contents);
  // Close the file and write the contents to disk.
  await writable.close();

  // getFile
  fileHandleL2_1.getFile().then((r) => console.log("fileHandle file:", r));
  fileHandleL2_2.getFile().then((r) => console.log("fileHandleL2_2 file:", r));

  // 文件删除
  fileHandleL2_1.remove();
  fileHandleL2_2.remove();

  // 目录删除文件
  dirHandleL2.removeEntry("测试文件夹1的子文件夹1的文件.txt");
  dirHandleL2.removeEntry("测试文件夹1的子文件夹1的文件2.txt")

  // 目录删除
  dirHandleL2.remove({
    recursive: true
  })

  rootDir.remove({ recursive: true })
}

TODO::

  • [x] 分离基础数据和二进制文件 (2025-04-21)
  • [x] 改进基础数据存储,方便查询 (2025-04-22)
  • [ ] 改进 entries(), values(), keys() 真游标?(??咱可不改进,因为查询的改进)