iobroker.mywebui 1.42.31 → 1.42.32
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/io-package.json
CHANGED
package/package.json
CHANGED
|
@@ -587,19 +587,51 @@ export class IobrokerHandler {
|
|
|
587
587
|
}
|
|
588
588
|
async _getObjectFromFile(name) {
|
|
589
589
|
const file = await this.connection.readFile(this.namespaceFiles, name, false);
|
|
590
|
+
let bytes;
|
|
590
591
|
if (file.mimeType == 'application/json' || file.mimeType == 'text/javascript') {
|
|
591
592
|
return JSON.parse(file.file);
|
|
593
|
+
} else if (file.mimeType == 'application/octet-stream' && file.file instanceof ArrayBuffer) {
|
|
594
|
+
bytes = new Uint8Array(file.file);
|
|
595
|
+
} else {
|
|
596
|
+
bytes = Uint8Array.from(file.file.data);
|
|
592
597
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
598
|
+
// Gzip magic bytes 1f 8b — decompress transparently
|
|
599
|
+
if (bytes[0] === 0x1f && bytes[1] === 0x8b && window.DecompressionStream) {
|
|
600
|
+
bytes = await this._gunzipBytes(bytes);
|
|
596
601
|
}
|
|
597
|
-
|
|
598
|
-
return JSON.parse(dec.decode(Uint8Array.from(file.file.data)));
|
|
602
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
599
603
|
}
|
|
600
604
|
async _saveObjectToFile(obj, name) {
|
|
601
|
-
const
|
|
602
|
-
|
|
605
|
+
const bytes = new TextEncoder().encode(JSON.stringify(obj));
|
|
606
|
+
// Compress files >512 KB to prevent WebSocket message overflow
|
|
607
|
+
if (bytes.length > 512 * 1024 && window.CompressionStream) {
|
|
608
|
+
const compressed = await this._gzipBytes(bytes);
|
|
609
|
+
await this.connection.writeFile64(this.namespaceFiles, name, compressed.buffer);
|
|
610
|
+
} else {
|
|
611
|
+
await this.connection.writeFile64(this.namespaceFiles, name, bytes);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
async _gzipBytes(bytes) {
|
|
615
|
+
const cs = new CompressionStream('gzip');
|
|
616
|
+
const w = cs.writable.getWriter();
|
|
617
|
+
w.write(bytes); w.close();
|
|
618
|
+
const r = cs.readable.getReader();
|
|
619
|
+
const chunks = []; let res;
|
|
620
|
+
while (!(res = await r.read()).done) chunks.push(res.value);
|
|
621
|
+
const out = new Uint8Array(chunks.reduce((s, c) => s + c.length, 0));
|
|
622
|
+
let off = 0; for (const c of chunks) { out.set(c, off); off += c.length; }
|
|
623
|
+
return out;
|
|
624
|
+
}
|
|
625
|
+
async _gunzipBytes(bytes) {
|
|
626
|
+
const ds = new DecompressionStream('gzip');
|
|
627
|
+
const w = ds.writable.getWriter();
|
|
628
|
+
w.write(bytes); w.close();
|
|
629
|
+
const r = ds.readable.getReader();
|
|
630
|
+
const chunks = []; let res;
|
|
631
|
+
while (!(res = await r.read()).done) chunks.push(res.value);
|
|
632
|
+
const out = new Uint8Array(chunks.reduce((s, c) => s + c.length, 0));
|
|
633
|
+
let off = 0; for (const c of chunks) { out.set(c, off); off += c.length; }
|
|
634
|
+
return out;
|
|
603
635
|
}
|
|
604
636
|
async _saveBinaryToFile(binary, name) {
|
|
605
637
|
await this.connection.writeFile64(this.namespaceFiles, name, await binary.arrayBuffer());
|