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 all 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
78 changes: 64 additions & 14 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 All @@ -156,42 +176,72 @@ If you want to listener the upload results, you can pass in the callback functio

```js
await flatDirectory.upload(key, data, {
onProgress: function (progress, count) {
console.log(`Uploaded ${progress} of ${totalCount} chunks`);
onProgress: function (progress, count, isChange) {
console.log(`Uploaded ${progress} of ${count} chunks`);
},
onFail: function (err) {
console.log(err);
},
onSuccess: function (totalUploadChunks, totalUploadSize, totalStorageCost) {
onFinish: function (totalUploadChunks, totalUploadSize, totalStorageCost) {
console.log(`Total upload chunk count is ${totalUploadChunks}, size is ${totalUploadSize}, storage cost is ${totalStorageCost}`);
}
});
```

#### download
#### uploadFile

Download data from the EthStorage network.
Upload file object to FlatDirectory.

```js
const key = "test.txt";
const data = await flatDirectory.download(key);
Browser
```javascript
// <input id='fileToUpload' />
const file = document.getElementById('fileToUpload').files[0];
await flatDirectory.uploadFile(key, file, {
onProgress: function (progress, count, isChange) {
console.log(`Uploaded ${progress} of ${count} chunks`);
},
onFail: function (err) {
console.log(err);
},
onFinish: function (totalUploadChunks, totalUploadSize, totalStorageCost) {
console.log(`Total upload chunk count is ${totalUploadChunks}, size is ${totalUploadSize}, storage cost is ${totalStorageCost}`);
}
});
```

#### downloadSync
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, isChange) {
console.log(`Uploaded ${progress} of ${count} chunks`);
},
onFail: function (err) {
console.log(err);
},
onFinish: 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

If you want to listener the download progress, you can pass in the callback function.

```js
const key = "test.txt";
flatDirectory.download(key, {
onProgress: function (progress, totalCount, chunk) {
console.log(`Download ${progress} of ${totalCount} chunks, this chunk is ${chunk.toString()}`);
await flatDirectory.download(key, {
onProgress: function (progress, count, chunk) {
console.log(`Download ${progress} of ${count} chunks, this chunk is ${chunk.toString()}`);
},
onFail: function (error) {
console.error("Error download data:", error);
},
onSuccess: function (data) {
console.log("Download success.", data);
onFinish: function () {
console.log("Download success.");
}
});
```
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
32 changes: 20 additions & 12 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@ import resolve from '@rollup/plugin-node-resolve';

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

Loading