tasmota-webserial-esptool 9.2.19 → 9.2.21

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.
package/src/util.ts CHANGED
@@ -54,5 +54,25 @@ export const formatMacAddr = (macAddr: number[]): string => {
54
54
  .join(":");
55
55
  };
56
56
 
57
+ /**
58
+ * @name padTo
59
+ * Pad data to the next alignment boundary with the given fill byte (default 0xFF)
60
+ */
61
+ export function padTo(
62
+ data: Uint8Array,
63
+ alignment: number,
64
+ padCharacter = 0xff,
65
+ ): Uint8Array {
66
+ const padMod = data.length % alignment;
67
+ if (padMod !== 0) {
68
+ const padding = new Uint8Array(alignment - padMod).fill(padCharacter);
69
+ const paddedData = new Uint8Array(data.length + padding.length);
70
+ paddedData.set(data);
71
+ paddedData.set(padding, data.length);
72
+ return paddedData;
73
+ }
74
+ return data;
75
+ }
76
+
57
77
  export const sleep = (ms: number) =>
58
78
  new Promise((resolve) => setTimeout(resolve, ms));