Skip to content

Commit

Permalink
Merge branch 'main' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 committed Oct 30, 2023
2 parents 3b89d02 + 91ca102 commit baa4591
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 14 deletions.
41 changes: 40 additions & 1 deletion packages/file-handle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,43 @@

WASM module that handle file, such as `checksums` method.

* [ ] Nodejs `checksums` need support pass Buffer
## Usage on Nodejs

```javascript
const fs = require('fs')
const { getCheckSums } = require('@bnb-chain/greenfiled-file-handle');
const fileBuffer = fs.readFileSync('./CHANGELOG.md');

(async () => {
const { contentLength, expectCheckSums } = await getCheckSums(fileBuffer);
})()
```

Full Code: https://github.com/bnb-chain/greenfield-js-sdk/blob/main/examples/nodejs/storage.js

## Usage on Browser

load wasm:

```html
<script src="https://unpkg.com/@bnb-chain/[email protected]/dist/browser/umd/index.js"></script>
<script
window.__PUBLIC_FILE_HANDLE_WASM_PATH__ = 'https://unpkg.com/@bnb-chain/[email protected]/dist/node/file-handle.wasm'`,
}}
></script>
```

execute wasm:

```javascript
(async () => {
// file is from input element
const fileBytes = await file.arrayBuffer();
const hashResult = await (window as any).FileHandle.getCheckSums(
new Uint8Array(fileBytes),
);
const { contentLength, expectCheckSums } = hashResult;
})()
```

Full Code: https://github.com/bnb-chain/greenfield-js-sdk/blob/main/examples/nextjs/src/components/object/create/index.tsx#L63
140 changes: 127 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit baa4591

Please sign in to comment.