-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |