@altronix/webtobin 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/webtobin.mjs +5 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altronix/webtobin",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "./webtobin.mjs",
package/webtobin.mjs CHANGED
@@ -62,7 +62,7 @@ export default class Webtobin {
62
62
  */
63
63
  print() {
64
64
  this.files.sort((a, b) => a.path.localeCompare(b.path));
65
- let arr;
65
+ let arr = new Uint8Array([]);
66
66
  for (const item of this.files) {
67
67
  const encoder = new TextEncoder();
68
68
  const path = encoder.encode(item.path);
@@ -74,14 +74,10 @@ export default class Webtobin {
74
74
  path.forEach((v, idx) => view.setUint8(idx + 4, v));
75
75
  view.setUint8(path.length + 4, 0);
76
76
  item.data.forEach((v, idx) => view.setUint8(idx + path.length + 5, v));
77
- if (!arr) {
78
- arr = new Uint8Array(view.buffer);
79
- } else {
80
- const next = new Uint8Array(arr.length + view.byteLength);
81
- next.set(arr, 0);
82
- next.set(new Uint8Array(view.buffer), arr.length);
83
- arr = next;
84
- }
77
+ const next = new Uint8Array(arr.length + view.byteLength);
78
+ next.set(arr, 0);
79
+ next.set(new Uint8Array(view.buffer), arr.length);
80
+ arr = next;
85
81
  }
86
82
  let ret = new Uint8Array(arr.length + 4);
87
83
  ret.set(arr, 0);