@altronix/webtobin 0.2.0 → 0.4.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.
- package/package.json +1 -1
- package/webtobin.d.ts +3 -1
- package/webtobin.mjs +15 -5
package/package.json
CHANGED
package/webtobin.d.ts
CHANGED
package/webtobin.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/** Class holding Webtobin state */
|
|
4
4
|
export default class Webtobin {
|
|
5
5
|
constructor() {
|
|
6
|
-
this.
|
|
6
|
+
this.files = [];
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -42,7 +42,17 @@ export default class Webtobin {
|
|
|
42
42
|
} else {
|
|
43
43
|
arr = data;
|
|
44
44
|
}
|
|
45
|
-
this.
|
|
45
|
+
this.files.push({ path, data: arr });
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Remove a file from the bin
|
|
51
|
+
* @param {string} path the file location to remove
|
|
52
|
+
* @return {Webtobin}
|
|
53
|
+
*/
|
|
54
|
+
remove(path) {
|
|
55
|
+
this.files = this.files.filter((a) => !(a.path === path));
|
|
46
56
|
return this;
|
|
47
57
|
}
|
|
48
58
|
|
|
@@ -50,10 +60,10 @@ export default class Webtobin {
|
|
|
50
60
|
* Sort and build binary
|
|
51
61
|
* @return {Uint8Array}
|
|
52
62
|
*/
|
|
53
|
-
|
|
54
|
-
this.
|
|
63
|
+
print() {
|
|
64
|
+
this.files.sort((a, b) => a.path.localeCompare(b.path));
|
|
55
65
|
let arr;
|
|
56
|
-
for (const item of this.
|
|
66
|
+
for (const item of this.files) {
|
|
57
67
|
const encoder = new TextEncoder();
|
|
58
68
|
const path = encoder.encode(item.path);
|
|
59
69
|
const len = path.length + item.data.length + 1;
|