Skip to content

Commit

Permalink
feat: blockstore-opfs
Browse files Browse the repository at this point in the history
  • Loading branch information
tabcat committed Jul 26, 2024
1 parent 7cce494 commit 9834731
Show file tree
Hide file tree
Showing 15 changed files with 1,077 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/blockstore-opfs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This project is dual licensed under MIT and Apache-2.0.

MIT: https://www.opensource.org/licenses/mit
Apache-2.0: https://www.apache.org/licenses/license-2.0
5 changes: 5 additions & 0 deletions packages/blockstore-opfs/LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
19 changes: 19 additions & 0 deletions packages/blockstore-opfs/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
35 changes: 35 additions & 0 deletions packages/blockstore-opfs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-stores.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-stores)
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-stores/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/js-stores/actions/workflows/js-test-and-release.yml?query=branch%3Amain)

> Blockstore implementation with Origin Private Filesystem backend.
# Install

```console
$ npm i blockstore-opfs
```

# API Docs

- <https://ipfs.github.io/js-stores/modules/blockstore_opfs.html>

# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

# Contribute

Contributions welcome! Please check out [the issues](https://github.com/ipfs/js-stores/issues).

Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.

Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
18 changes: 18 additions & 0 deletions packages/blockstore-opfs/benchmarks/encoding/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "benchmarks-encoding",
"version": "1.0.0",
"main": "index.js",
"private": true,
"type": "module",
"scripts": {
"clean": "aegir clean",
"build": "aegir build --bundle false",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"start": "npm run build && node dist/src/index.js"
},
"devDependencies": {
"multiformats": "^11.0.1",
"tinybench": "^2.4.0"
}
}
31 changes: 31 additions & 0 deletions packages/blockstore-opfs/benchmarks/encoding/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Encoding Benchmark

Multiformats ships a number of base encoding algorithms. This module has no strong opinion
on which is best, as long as it is case insensitive, so benchmark them to choose the fastest.

At the time of writing `base8` is the fastest, followed other alorithms using `rfc4648` encoding
internally in `multiformats` (e.g. `base16`, `base32`), and finally anything using `baseX` encoding.

We choose base32upper which uses `rfc4648` because it has a longer alphabet so will shard better.

## Usage

```console
$ npm i
$ npm start

> benchmarks-gc@1.0.0 start
> npm run build && node dist/src/index.js


> benchmarks-gc@1.0.0 build
> aegir build --bundle false

[14:51:28] tsc [started]
[14:51:33] tsc [completed]
generating Ed25519 keypair...
┌─────────┬────────────────┬─────────┬───────────┬──────┐
│ (index) │ Implementation │ ops/s │ ms/op │ runs │
├─────────┼────────────────┼─────────┼───────────┼──────┤
//... results here
```
73 changes: 73 additions & 0 deletions packages/blockstore-opfs/benchmarks/encoding/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { base10 } from 'multiformats/bases/base10'
import { base16upper } from 'multiformats/bases/base16'
import { base256emoji } from 'multiformats/bases/base256emoji'
import { base32, base32upper, base32hexupper, base32z } from 'multiformats/bases/base32'
import { base36, base36upper } from 'multiformats/bases/base36'
import { base8 } from 'multiformats/bases/base8'
import { CID } from 'multiformats/cid'
import { Bench } from 'tinybench'

const RESULT_PRECISION = 2

const cid = CID.parse('QmeimKZyjcBnuXmAD9zMnSjM9JodTbgGT3gutofkTqz9rE')

async function main (): Promise<void> {
const suite = new Bench()
suite.add('base8', () => {
base8.encode(cid.bytes)
})
suite.add('base10', () => {
base10.encode(cid.bytes)
})
suite.add('base16upper', () => {
base16upper.encode(cid.bytes)
})
suite.add('base32', () => {
base32.encode(cid.bytes)
})
suite.add('base32upper', () => {
base32upper.encode(cid.bytes)
})
suite.add('base32hexupper', () => {
base32hexupper.encode(cid.bytes)
})
suite.add('base32z', () => {
base32z.encode(cid.bytes)
})
suite.add('base36', () => {
base36.encode(cid.bytes)
})
suite.add('base36upper', () => {
base36upper.encode(cid.bytes)
})
suite.add('base256emoji', () => {
base256emoji.encode(cid.bytes)
})

await suite.run()

console.table(suite.tasks.sort((a, b) => { // eslint-disable-line no-console
const resultA = a.result?.hz ?? 0
const resultB = b.result?.hz ?? 0

if (resultA === resultB) {
return 0
}

if (resultA < resultB) {
return 1
}

return -1
}).map(({ name, result }) => ({
Implementation: name,
'ops/s': parseFloat(result?.hz.toFixed(RESULT_PRECISION) ?? '0'),
'ms/op': parseFloat(result?.period.toFixed(RESULT_PRECISION) ?? '0'),
runs: result?.samples.length
})))
}

main().catch(err => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
})
13 changes: 13 additions & 0 deletions packages/blockstore-opfs/benchmarks/encoding/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "aegir/src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist",
"target": "ES2022",
"module": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"]
},
"include": [
"src",
"test"
]
}
175 changes: 175 additions & 0 deletions packages/blockstore-opfs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
{
"name": "blockstore-opfs",
"version": "1.1.8",
"description": "Blockstore implementation with file system backend",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/ipfs/js-stores/tree/master/packages/blockstore-fs#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/ipfs/js-stores.git"
},
"bugs": {
"url": "https://github.com/ipfs/js-stores/issues"
},
"keywords": [
"datastore",
"fs",
"interface",
"ipfs",
"key-value"
],
"type": "module",
"types": "./dist/src/index.d.ts",
"typesVersions": {
"*": {
"*": [
"*",
"dist/*",
"dist/src/*",
"dist/src/*/index"
],
"src/*": [
"*",
"dist/*",
"dist/src/*",
"dist/src/*/index"
]
}
},
"files": [
"src",
"dist",
"!dist/test",
"!**/*.tsbuildinfo"
],
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js"
},
"./sharding": {
"types": "./dist/src/sharding.d.ts",
"import": "./dist/src/sharding.js"
}
},
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"project": [
"tsconfig.json",
"benchmarks/encoding/tsconfig.json"
],
"sourceType": "module",
"lib": ["DOM"]
}
},
"release": {
"branches": [
"main"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"breaking": true,
"release": "major"
},
{
"revert": true,
"release": "patch"
},
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"type": "deps",
"release": "patch"
},
{
"scope": "no-release",
"release": false
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Trivial Changes"
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "deps",
"section": "Dependencies"
},
{
"type": "test",
"section": "Tests"
}
]
}
}
],
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
]
},
"scripts": {
"clean": "aegir clean",
"lint": "aegir lint",
"build": "aegir build --bundle false",
"release": "aegir release",
"test": "aegir test -t browser",
"test:chrome": "aegir test -t browser",
"test:chrome-webworker": "aegir test -t webworker",
"test:firefox": "aegir test -t browser -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
"dep-check": "aegir dep-check"
},
"dependencies": {
"blockstore-core": "^4.0.0",
"interface-blockstore": "^5.0.0",
"interface-store": "^5.0.0",
"it-map": "^3.0.1",
"it-parallel-batch": "^3.0.0",
"multiformats": "^12.0.1"
},
"devDependencies": {
"aegir": "^41.1.9",
"interface-blockstore-tests": "^6.0.0"
}
}
Loading

0 comments on commit 9834731

Please sign in to comment.