Skip to content

Commit

Permalink
dev: compress default image with brotli
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Sep 22, 2024
1 parent 3ce8da3 commit 27b6625
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/emulator/image/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ sudo losetup -d "$loop"
rm "$OUT_ROOTFS_TAR"
rm -rf "$OUT_ROOTFS_MNT"

cd "$IMAGES"
brotli -q 6 rootfs.bin
cd -

echo "done! created"
sudo chown -R $USER:$USER $IMAGES/boot
3 changes: 3 additions & 0 deletions src/emulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"description": "",
"devDependencies": {
"html-webpack-plugin": "^5.6.0"
},
"dependencies": {
"brotli-dec-wasm": "^2.3.0"
}
}
14 changes: 12 additions & 2 deletions src/emulator/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const {
DataBuilder,
} = require("../../puter-wisp/src/exports");

const brotliCJS = require('brotli-dec-wasm');

const status = {
ready: false,
};
Expand Down Expand Up @@ -132,9 +134,17 @@ window.onload = async function()
}

const resp = await fetch(
'./image/build/rootfs.bin'
'./image/build/rootfs.bin.br'
);
const arrayBuffer = await resp.arrayBuffer();

const brotli = await brotliCJS.default;

const utf8Array = new Uint8Array(arrayBuffer);
console.log('whats in here??', brotli);
const decompressed = brotli.decompress(utf8Array);
const decompressedArrayBuffer = decompressed.buffer;

var emulator = window.emulator = new V86({
wasm_path: PATH_V86 + "/v86.wasm",
memory_size: 512 * 1024 * 1024,
Expand Down Expand Up @@ -164,7 +174,7 @@ window.onload = async function()
// url: "./image/build/rootfs.bin",
// },
hda: {
buffer: arrayBuffer,
buffer: decompressedArrayBuffer,
// url: './image/build/rootfs.bin',
async: true,
// size: 1073741824,
Expand Down

0 comments on commit 27b6625

Please sign in to comment.