Skip to content

Commit 15d2b96

Browse files
author
Sarah Wang
committed
add zstd support
Signed-off-by: Sarah Wang <sarah.wang_1@nxp.com>
1 parent 5a9bb46 commit 15d2b96

8 files changed

Lines changed: 354 additions & 10 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ CMakeCache.txt
1414
*.clst
1515
*.snap
1616
node_modules
17-
build
17+
build
18+
*-lock.json

webusb/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
window.ZstdCodec = require('zstd-codec').ZstdCodec;
2+
require("zstd-codec/lib/module.js").run((binding) => {console.log("running", binding); window.binding = binding} )
3+
// require("../libwebusb/module.js").run((binding) => {window.binding = binding} )
4+
// require("./node_modules/zstd-codec/lib/module.js").run((binding) => {window.binding = binding} )
5+
// window.binding = "test";
6+
// window.fs = require('fs');

webusb/package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,24 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"-": "^0.0.1",
67
"@testing-library/jest-dom": "^5.16.5",
78
"@testing-library/react": "^13.4.0",
89
"@testing-library/user-event": "^13.5.0",
10+
"fs": "^0.0.1-security",
11+
"g": "^2.0.1",
912
"react": "^18.2.0",
1013
"react-dom": "^18.2.0",
1114
"react-scripts": "^5.0.1",
12-
"web-vitals": "^2.1.4"
15+
"web-vitals": "^2.1.4",
16+
"zstd-codec": "^0.1.4"
1317
},
1418
"scripts": {
1519
"start": "react-scripts start",
16-
"build": "react-scripts build",
20+
"build": "react-scripts build; browserify index.js -o build/bundle.js -t babelify --presets es2015; ",
1721
"test": "react-scripts test",
1822
"eject": "react-scripts eject"
1923
},
20-
"eslintConfig": {
21-
"extends": [
22-
"react-app",
23-
"react-app/jest"
24-
]
25-
},
2624
"browserslist": {
2725
"production": [
2826
">0.2%",
@@ -35,5 +33,8 @@
3533
"last 1 safari version"
3634
]
3735
},
38-
"proxy": "http://localhost:5000"
36+
"devDependencies": {
37+
"@babel/core": "^7.22.9",
38+
"babelify": "^10.0.0"
39+
}
3940
}

webusb/public/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@
2525
Learn how to configure a non-root public URL by running `npm run build`.
2626
-->
2727
<title>React App</title>
28+
<script src="bundle.js"></script>
2829
</head>
30+
2931
<body>
32+
<h1>Sample Applications</h1>
33+
<div id="container"></div>
34+
35+
3036
<noscript>You need to enable JavaScript to run this app.</noscript>
3137
<div id="root"></div>
3238
<!--

webusb/src/App.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState } from 'react';
22
import Combined from "./components/Combined";
3+
import Decompress2 from "./components/Decompress";
34
import usePopup from "./logic/usePopup";
45

56
import './App.css'
@@ -12,6 +13,9 @@ const App = () => {
1213
return (
1314
<div className="App">
1415
<div className="u-flex u-column">
16+
<div>
17+
<Decompress2 />
18+
</div>
1519
<div className="u-row">
1620
<span className="link-container">bootloader [optional]: </span>
1721
<span className="file-name">{bootFile? bootFile.name:""}</span>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useEffect, useState } from "react"
2+
import useDecompress from '../logic/useDecompress'
3+
import { DATA_SZ, BLK_SZ, PACKET_SZ } from "../helper/sparse";
4+
5+
const Decompress = () => {
6+
const [flashFile, setFlashFile] = useState();
7+
const [{
8+
requestUSBDevice,
9+
USBDevice,
10+
preBoot,
11+
send_chunk_headers,
12+
send_packet,
13+
send_flash,
14+
decompressFileToTransform,
15+
}] = useDecompress(flashFile);
16+
17+
useEffect(()=> {
18+
console.log(ZstdCodec)
19+
console.log(window.binding);
20+
}, [])
21+
22+
return (
23+
<div>
24+
file to decompress:
25+
<input type="file" onChange={(e) => setFlashFile(e.target.files[0])}/>
26+
27+
<button onClick={requestUSBDevice}>Pair USBDevice </button>
28+
</div>
29+
)
30+
}
31+
32+
export default Decompress

webusb/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ReactDOM from 'react-dom/client';
33
import './index.css';
44
import App from './App';
55
import reportWebVitals from './reportWebVitals';
6+
// import * as Z from 'zstd-codec'
67

78
const root = ReactDOM.createRoot(document.getElementById('root'));
89
root.render(

0 commit comments

Comments
 (0)