Skip to content

Commit 9834731

Browse files
committed
feat: blockstore-opfs
1 parent 7cce494 commit 9834731

15 files changed

+1077
-0
lines changed

packages/blockstore-opfs/LICENSE

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This project is dual licensed under MIT and Apache-2.0.
2+
3+
MIT: https://www.opensource.org/licenses/mit
4+
Apache-2.0: https://www.apache.org/licenses/license-2.0
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
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
2+
3+
http://www.apache.org/licenses/LICENSE-2.0
4+
5+
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.

packages/blockstore-opfs/LICENSE-MIT

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The MIT License (MIT)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

packages/blockstore-opfs/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
2+
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
3+
[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-stores.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-stores)
4+
[![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)
5+
6+
> Blockstore implementation with Origin Private Filesystem backend.
7+
8+
# Install
9+
10+
```console
11+
$ npm i blockstore-opfs
12+
```
13+
14+
# API Docs
15+
16+
- <https://ipfs.github.io/js-stores/modules/blockstore_opfs.html>
17+
18+
# License
19+
20+
Licensed under either of
21+
22+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
23+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
24+
25+
# Contribute
26+
27+
Contributions welcome! Please check out [the issues](https://github.com/ipfs/js-stores/issues).
28+
29+
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.
30+
31+
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).
32+
33+
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.
34+
35+
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "benchmarks-encoding",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"private": true,
6+
"type": "module",
7+
"scripts": {
8+
"clean": "aegir clean",
9+
"build": "aegir build --bundle false",
10+
"lint": "aegir lint",
11+
"dep-check": "aegir dep-check",
12+
"start": "npm run build && node dist/src/index.js"
13+
},
14+
"devDependencies": {
15+
"multiformats": "^11.0.1",
16+
"tinybench": "^2.4.0"
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Encoding Benchmark
2+
3+
Multiformats ships a number of base encoding algorithms. This module has no strong opinion
4+
on which is best, as long as it is case insensitive, so benchmark them to choose the fastest.
5+
6+
At the time of writing `base8` is the fastest, followed other alorithms using `rfc4648` encoding
7+
internally in `multiformats` (e.g. `base16`, `base32`), and finally anything using `baseX` encoding.
8+
9+
We choose base32upper which uses `rfc4648` because it has a longer alphabet so will shard better.
10+
11+
## Usage
12+
13+
```console
14+
$ npm i
15+
$ npm start
16+
17+
> benchmarks-gc@1.0.0 start
18+
> npm run build && node dist/src/index.js
19+
20+
21+
> benchmarks-gc@1.0.0 build
22+
> aegir build --bundle false
23+
24+
[14:51:28] tsc [started]
25+
[14:51:33] tsc [completed]
26+
generating Ed25519 keypair...
27+
┌─────────┬────────────────┬─────────┬───────────┬──────┐
28+
│ (index) │ Implementation │ ops/s │ ms/op │ runs │
29+
├─────────┼────────────────┼─────────┼───────────┼──────┤
30+
//... results here
31+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { base10 } from 'multiformats/bases/base10'
2+
import { base16upper } from 'multiformats/bases/base16'
3+
import { base256emoji } from 'multiformats/bases/base256emoji'
4+
import { base32, base32upper, base32hexupper, base32z } from 'multiformats/bases/base32'
5+
import { base36, base36upper } from 'multiformats/bases/base36'
6+
import { base8 } from 'multiformats/bases/base8'
7+
import { CID } from 'multiformats/cid'
8+
import { Bench } from 'tinybench'
9+
10+
const RESULT_PRECISION = 2
11+
12+
const cid = CID.parse('QmeimKZyjcBnuXmAD9zMnSjM9JodTbgGT3gutofkTqz9rE')
13+
14+
async function main (): Promise<void> {
15+
const suite = new Bench()
16+
suite.add('base8', () => {
17+
base8.encode(cid.bytes)
18+
})
19+
suite.add('base10', () => {
20+
base10.encode(cid.bytes)
21+
})
22+
suite.add('base16upper', () => {
23+
base16upper.encode(cid.bytes)
24+
})
25+
suite.add('base32', () => {
26+
base32.encode(cid.bytes)
27+
})
28+
suite.add('base32upper', () => {
29+
base32upper.encode(cid.bytes)
30+
})
31+
suite.add('base32hexupper', () => {
32+
base32hexupper.encode(cid.bytes)
33+
})
34+
suite.add('base32z', () => {
35+
base32z.encode(cid.bytes)
36+
})
37+
suite.add('base36', () => {
38+
base36.encode(cid.bytes)
39+
})
40+
suite.add('base36upper', () => {
41+
base36upper.encode(cid.bytes)
42+
})
43+
suite.add('base256emoji', () => {
44+
base256emoji.encode(cid.bytes)
45+
})
46+
47+
await suite.run()
48+
49+
console.table(suite.tasks.sort((a, b) => { // eslint-disable-line no-console
50+
const resultA = a.result?.hz ?? 0
51+
const resultB = b.result?.hz ?? 0
52+
53+
if (resultA === resultB) {
54+
return 0
55+
}
56+
57+
if (resultA < resultB) {
58+
return 1
59+
}
60+
61+
return -1
62+
}).map(({ name, result }) => ({
63+
Implementation: name,
64+
'ops/s': parseFloat(result?.hz.toFixed(RESULT_PRECISION) ?? '0'),
65+
'ms/op': parseFloat(result?.period.toFixed(RESULT_PRECISION) ?? '0'),
66+
runs: result?.samples.length
67+
})))
68+
}
69+
70+
main().catch(err => {
71+
console.error(err) // eslint-disable-line no-console
72+
process.exit(1)
73+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "aegir/src/config/tsconfig.aegir.json",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"target": "ES2022",
6+
"module": "ES2022",
7+
"lib": ["ES2022", "DOM", "DOM.Iterable"]
8+
},
9+
"include": [
10+
"src",
11+
"test"
12+
]
13+
}

packages/blockstore-opfs/package.json

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
{
2+
"name": "blockstore-opfs",
3+
"version": "1.1.8",
4+
"description": "Blockstore implementation with file system backend",
5+
"license": "Apache-2.0 OR MIT",
6+
"homepage": "https://github.com/ipfs/js-stores/tree/master/packages/blockstore-fs#readme",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/ipfs/js-stores.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/ipfs/js-stores/issues"
13+
},
14+
"keywords": [
15+
"datastore",
16+
"fs",
17+
"interface",
18+
"ipfs",
19+
"key-value"
20+
],
21+
"type": "module",
22+
"types": "./dist/src/index.d.ts",
23+
"typesVersions": {
24+
"*": {
25+
"*": [
26+
"*",
27+
"dist/*",
28+
"dist/src/*",
29+
"dist/src/*/index"
30+
],
31+
"src/*": [
32+
"*",
33+
"dist/*",
34+
"dist/src/*",
35+
"dist/src/*/index"
36+
]
37+
}
38+
},
39+
"files": [
40+
"src",
41+
"dist",
42+
"!dist/test",
43+
"!**/*.tsbuildinfo"
44+
],
45+
"exports": {
46+
".": {
47+
"types": "./dist/src/index.d.ts",
48+
"import": "./dist/src/index.js"
49+
},
50+
"./sharding": {
51+
"types": "./dist/src/sharding.d.ts",
52+
"import": "./dist/src/sharding.js"
53+
}
54+
},
55+
"eslintConfig": {
56+
"extends": "ipfs",
57+
"parserOptions": {
58+
"project": [
59+
"tsconfig.json",
60+
"benchmarks/encoding/tsconfig.json"
61+
],
62+
"sourceType": "module",
63+
"lib": ["DOM"]
64+
}
65+
},
66+
"release": {
67+
"branches": [
68+
"main"
69+
],
70+
"plugins": [
71+
[
72+
"@semantic-release/commit-analyzer",
73+
{
74+
"preset": "conventionalcommits",
75+
"releaseRules": [
76+
{
77+
"breaking": true,
78+
"release": "major"
79+
},
80+
{
81+
"revert": true,
82+
"release": "patch"
83+
},
84+
{
85+
"type": "feat",
86+
"release": "minor"
87+
},
88+
{
89+
"type": "fix",
90+
"release": "patch"
91+
},
92+
{
93+
"type": "docs",
94+
"release": "patch"
95+
},
96+
{
97+
"type": "test",
98+
"release": "patch"
99+
},
100+
{
101+
"type": "deps",
102+
"release": "patch"
103+
},
104+
{
105+
"scope": "no-release",
106+
"release": false
107+
}
108+
]
109+
}
110+
],
111+
[
112+
"@semantic-release/release-notes-generator",
113+
{
114+
"preset": "conventionalcommits",
115+
"presetConfig": {
116+
"types": [
117+
{
118+
"type": "feat",
119+
"section": "Features"
120+
},
121+
{
122+
"type": "fix",
123+
"section": "Bug Fixes"
124+
},
125+
{
126+
"type": "chore",
127+
"section": "Trivial Changes"
128+
},
129+
{
130+
"type": "docs",
131+
"section": "Documentation"
132+
},
133+
{
134+
"type": "deps",
135+
"section": "Dependencies"
136+
},
137+
{
138+
"type": "test",
139+
"section": "Tests"
140+
}
141+
]
142+
}
143+
}
144+
],
145+
"@semantic-release/changelog",
146+
"@semantic-release/npm",
147+
"@semantic-release/github",
148+
"@semantic-release/git"
149+
]
150+
},
151+
"scripts": {
152+
"clean": "aegir clean",
153+
"lint": "aegir lint",
154+
"build": "aegir build --bundle false",
155+
"release": "aegir release",
156+
"test": "aegir test -t browser",
157+
"test:chrome": "aegir test -t browser",
158+
"test:chrome-webworker": "aegir test -t webworker",
159+
"test:firefox": "aegir test -t browser -- --browser firefox",
160+
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
161+
"dep-check": "aegir dep-check"
162+
},
163+
"dependencies": {
164+
"blockstore-core": "^4.0.0",
165+
"interface-blockstore": "^5.0.0",
166+
"interface-store": "^5.0.0",
167+
"it-map": "^3.0.1",
168+
"it-parallel-batch": "^3.0.0",
169+
"multiformats": "^12.0.1"
170+
},
171+
"devDependencies": {
172+
"aegir": "^41.1.9",
173+
"interface-blockstore-tests": "^6.0.0"
174+
}
175+
}

0 commit comments

Comments
 (0)