Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support big data #6

Merged
merged 10 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ const cost = await flatDirectory.estimateCost(key, data);
console.log(`Gas Cost: ${cost.gasCost}, Storage Cost: ${cost.storageCost}`);
```

#### estimateFileCost

Estimate gas costs before uploading.

Browser
```javascript
// <input id='fileToUpload' />
const file = document.getElementById('fileToUpload').files[0];
const cost = await flatDirectory.estimateFileCost("example1.txt", file);
console.log(`Gas Cost: ${cost.gasCost}, Storage Cost: ${cost.storageCost}`);
```

Node
```javascript
const {NodeFile} = require("ethstorage-sdk/file");
const file = new NodeFile("/usr/download/test.jpg");
const cost = await flatDirectory.estimateFileCost("example1.txt", file);
console.log(`Gas Cost: ${cost.gasCost}, Storage Cost: ${cost.storageCost}`);
```

#### upload

Upload data to FlatDirectory.
Expand Down Expand Up @@ -168,6 +188,45 @@ await flatDirectory.upload(key, data, {
});
```

#### uploadFile

Upload file object to FlatDirectory.

Browser
```javascript
// <input id='fileToUpload' />
const file = document.getElementById('fileToUpload').files[0];
await flatDirectory.uploadFile(key, file, {
onProgress: function (progress, count) {
console.log(`Uploaded ${progress} of ${totalCount} chunks`);
iteyelmp marked this conversation as resolved.
Show resolved Hide resolved
},
onFail: function (err) {
console.log(err);
},
onSuccess: function (totalUploadChunks, totalUploadSize, totalStorageCost) {
console.log(`Total upload chunk count is ${totalUploadChunks}, size is ${totalUploadSize}, storage cost is ${totalStorageCost}`);
}
});
```

Node
```javascript
const {NodeFile} = require("ethstorage-sdk/file");
const file = new NodeFile("/usr/download/test.jpg");
await flatDirectory.uploadFile(key, file, {
onProgress: function (progress, count) {
console.log(`Uploaded ${progress} of ${totalCount} chunks`);
},
onFail: function (err) {
console.log(err);
},
onSuccess: function (totalUploadChunks, totalUploadSize, totalStorageCost) {
console.log(`Total upload chunk count is ${totalUploadChunks}, size is ${totalUploadSize}, storage cost is ${totalStorageCost}`);
}
});
```


iteyelmp marked this conversation as resolved.
Show resolved Hide resolved
#### download

Download data from the EthStorage network.
Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
"description": "eip-4844 blobs upload sdk",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"exports": {
".": {
"require": "./dist/index.cjs.js",
"import": "./dist/index.esm.js"
},
"./file": {
"require": "./dist/file.cjs.js"
}
},
"scripts": {
"build": "rollup -c"
},
Expand Down
7 changes: 5 additions & 2 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import resolve from '@rollup/plugin-node-resolve';

export default [
{
input: "./src/index.js",
input: {
'index.cjs': './src/index.js',
'file.cjs': './src/node/file.js',
},
output: {
file: 'dist/index.cjs.js', format: 'cjs', sourcemap: true
dir: 'dist', format: 'cjs', sourcemap: true
},
plugins: [commonjs(), resolve()],
external: ["ethers", "kzg-wasm"]
Expand Down
Loading