Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisjiang committed May 14, 2024
1 parent 4a3ce01 commit 87447dd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
26 changes: 20 additions & 6 deletions README.cn.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
# 快乐地使用 OPFS

[![NPM version](http://img.shields.io/npm/v/happy-opfs.svg)](https://npmjs.org/package/happy-opfs)
[![JSR Version](https://jsr.io/badges/@happy-js/happy-opfs)](https://jsr.io/@happy-js/happy-opfs)
[![JSR Score](https://jsr.io/badges/@happy-js/happy-opfs/score)](https://jsr.io/@happy-js/happy-opfs/score)

这是一套参考 [Deno Runtime File_System](https://deno.land/api#File_System)[Deno @std/fs](https://jsr.io/@std/fs) API,基于 OPFS 实现的浏览器可用的 fs 模块。

## 安装

通过 [JSR](https://jsr.io/@happy-js/happy-opfs) (**推荐**)
pnpm
```
pnpm add happy-opfs
```

yarn
```
npx jsr add @happy-js/happy-opfs
yarn add happy-opfs
```

或者直接使用 npm
npm
```
npm install --save happy-opfs
```

通过 JSR
```
jsr add @happy-js/happy-opfs
```

## 什么是 OPFS

OPFS 是 [Origin private file system](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system) 的简称,旨在为浏览器环境提供一套文件系统 API 来操作本地文件。
Expand All @@ -32,7 +46,7 @@ OPFS 是 [Origin private file system](https://developer.mozilla.org/en-US/docs/W
## 示例

```ts
import { appendFile, downloadFile, exists, isOPFSSupported, mkdir, readDir, readFile, readTextFile, remove, rename, stat, uploadFile, writeFile } from '@happy-js/happy-opfs';
import { appendFile, downloadFile, exists, isOPFSSupported, mkdir, readDir, readFile, readTextFile, remove, rename, stat, uploadFile, writeFile } from 'happy-opfs';

// Check if OPFS is supported
console.log(`OPFS is${ isOPFSSupported() ? '' : ' not' } supported`);
Expand Down Expand Up @@ -86,8 +100,8 @@ for await (const [name, handle] of (await readDir('/')).unwrap()) {
```
git clone https://github.com/JiangJie/happy-opfs.git
cd happy-opfs
npm ci
npm start
pnpm install
pnpm start
```

通过浏览器打开 [https://localhost:8443/](https://localhost:8443/),打开开发者工具观察 console 的输出。
Expand Down
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
<p align="center">
<a href="README.cn.md">[中文]</a>
</p>

# Use OPFS happily

[![NPM version](http://img.shields.io/npm/v/happy-opfs.svg)](https://npmjs.org/package/happy-opfs)
[![JSR Version](https://jsr.io/badges/@happy-js/happy-opfs)](https://jsr.io/@happy-js/happy-opfs)
[![JSR Score](https://jsr.io/badges/@happy-js/happy-opfs/score)](https://jsr.io/@happy-js/happy-opfs/score)

---

<a href="README.cn.md">[中文]</a>

---

This is a browser-compatible fs module based on OPFS, which references the [Deno Runtime File_System](https://deno.land/api#File_System) and [Deno @std/fs](https://jsr.io/@std/fs) APIs.

## Installation

Via [JSR](https://jsr.io/@happy-js/happy-opfs) (**recommand**)
via pnpm
```
npx jsr add @happy-js/happy-opfs
pnpm add happy-opfs
```

or via yarn
```
yarn add happy-opfs
```

or just from npm
```
npm install --save happy-opfs
```

via JSR
```
jsr add @happy-js/happy-opfs
```

## What is OPFS

OPFS stands for [Origin private file system](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system), which aims to provide a file system API for manipulating local files in the browser environment.
Expand All @@ -36,7 +52,7 @@ The return values of asynchronous APIs are of the [Result](https://github.com/Ji
## Examples

```ts
import { appendFile, downloadFile, exists, isOPFSSupported, mkdir, readDir, readFile, readTextFile, remove, rename, stat, uploadFile, writeFile } from '@happy-js/happy-opfs';
import { appendFile, downloadFile, exists, isOPFSSupported, mkdir, readDir, readFile, readTextFile, remove, rename, stat, uploadFile, writeFile } from 'happy-opfs';

// Check if OPFS is supported
console.log(`OPFS is${ isOPFSSupported() ? '' : ' not' } supported`);
Expand Down Expand Up @@ -90,8 +106,8 @@ You can find the above example code in the file `tests/index.ts`, or you can vie
```
git clone https://github.com/JiangJie/happy-opfs.git
cd happy-opfs
npm ci
npm start
pnpm install
pnpm start
```

Open [https://localhost:8443/](https://localhost:8443/) in your browser and open the developer tools to observe the console output.
Expand Down

0 comments on commit 87447dd

Please sign in to comment.