From 65333cdcae483eace027459b803a17f0f93a3be5 Mon Sep 17 00:00:00 2001
From: rk <59029880+rrr523@users.noreply.github.com>
Date: Thu, 21 Dec 2023 23:46:34 +0800
Subject: [PATCH] Feat/reed solomon (#446)
* chore: Update docs
* docs: Update
* docs: Update
* feat: Set Webworker
* feat: Clean InjectWorker
* feat: Clean InjectWorker
---
.changeset/mighty-laws-suffer.md | 5 ++
.changeset/tidy-boats-laugh.md | 5 ++
packages/reed-solomon/README.md | 40 ++++------
packages/reed-solomon/examples/node.js | 4 +-
.../reed-solomon/examples/web-worker.html | 29 +++----
packages/reed-solomon/src/index.js | 49 +++++++++---
packages/reed-solomon/src/node.adapter.js | 54 ++-----------
packages/reed-solomon/src/web.adapter.js | 79 +++++++++----------
packages/reed-solomon/types/index.d.ts | 10 +++
packages/reed-solomon/types/web.adapter.d.ts | 4 +-
10 files changed, 138 insertions(+), 141 deletions(-)
create mode 100644 .changeset/mighty-laws-suffer.md
create mode 100644 .changeset/tidy-boats-laugh.md
diff --git a/.changeset/mighty-laws-suffer.md b/.changeset/mighty-laws-suffer.md
new file mode 100644
index 00000000..58d65e3b
--- /dev/null
+++ b/.changeset/mighty-laws-suffer.md
@@ -0,0 +1,5 @@
+---
+'@bnb-chain/reed-solomon': minor
+---
+
+feat: Clean InjectWorker
diff --git a/.changeset/tidy-boats-laugh.md b/.changeset/tidy-boats-laugh.md
new file mode 100644
index 00000000..2a5e6476
--- /dev/null
+++ b/.changeset/tidy-boats-laugh.md
@@ -0,0 +1,5 @@
+---
+'@bnb-chain/reed-solomon': minor
+---
+
+feat: Support setting worker counts
diff --git a/packages/reed-solomon/README.md b/packages/reed-solomon/README.md
index c62133d1..ef9ca2be 100644
--- a/packages/reed-solomon/README.md
+++ b/packages/reed-solomon/README.md
@@ -33,7 +33,6 @@ Use directly in the browser via script tag:
get reed solomon
-
@@ -128,6 +122,6 @@ const res = await rs.encodeInWorker(__filename, Uint8Array.from(fileBuffer))
[Code](./examples/node-worker.js)
-## Benchark
+## Benchmark
[benchmark](./benchmark.md)
diff --git a/packages/reed-solomon/examples/node.js b/packages/reed-solomon/examples/node.js
index 372739bb..156e70f1 100644
--- a/packages/reed-solomon/examples/node.js
+++ b/packages/reed-solomon/examples/node.js
@@ -3,13 +3,13 @@ const fs = require('node:fs');
const path = require('node:path');
const { ReedSolomon } = require('../dist/index');
-const fileBuffer = fs.readFileSync('./README.md');
+const sourceData = fs.readFileSync('./README.md');
(async () => {
const rs = new ReedSolomon();
console.log('file size', sourceData.length / 1024 / 1024, 'm');
console.time('cost');
- const res = await rs.encode(Uint8Array.from(fileBuffer));
+ const res = await rs.encode(Uint8Array.from(sourceData));
console.log('res', res);
console.timeEnd('cost');
})();
diff --git a/packages/reed-solomon/examples/web-worker.html b/packages/reed-solomon/examples/web-worker.html
index eadede31..71989c9c 100644
--- a/packages/reed-solomon/examples/web-worker.html
+++ b/packages/reed-solomon/examples/web-worker.html
@@ -17,6 +17,12 @@