Skip to content

Commit

Permalink
add zstd support
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Wang <sarah.wang_1@nxp.com>
  • Loading branch information
Sarah Wang committed Jul 24, 2023
1 parent 5a9bb46 commit 15d2b96
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ CMakeCache.txt
*.clst
*.snap
node_modules
build
build
*-lock.json
6 changes: 6 additions & 0 deletions webusb/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
window.ZstdCodec = require('zstd-codec').ZstdCodec;
require("zstd-codec/lib/module.js").run((binding) => {console.log("running", binding); window.binding = binding} )
// require("../libwebusb/module.js").run((binding) => {window.binding = binding} )
// require("./node_modules/zstd-codec/lib/module.js").run((binding) => {window.binding = binding} )
// window.binding = "test";
// window.fs = require('fs');
19 changes: 10 additions & 9 deletions webusb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"-": "^0.0.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"fs": "^0.0.1-security",
"g": "^2.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"web-vitals": "^2.1.4"
"web-vitals": "^2.1.4",
"zstd-codec": "^0.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build": "react-scripts build; browserify index.js -o build/bundle.js -t babelify --presets es2015; ",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
Expand All @@ -35,5 +33,8 @@
"last 1 safari version"
]
},
"proxy": "http://localhost:5000"
"devDependencies": {
"@babel/core": "^7.22.9",
"babelify": "^10.0.0"
}
}
6 changes: 6 additions & 0 deletions webusb/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<script src="bundle.js"></script>
</head>

<body>
<h1>Sample Applications</h1>
<div id="container"></div>


<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
Expand Down
4 changes: 4 additions & 0 deletions webusb/src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import Combined from "./components/Combined";
import Decompress2 from "./components/Decompress";
import usePopup from "./logic/usePopup";

import './App.css'
Expand All @@ -12,6 +13,9 @@ const App = () => {
return (
<div className="App">
<div className="u-flex u-column">
<div>
<Decompress2 />
</div>
<div className="u-row">
<span className="link-container">bootloader [optional]: </span>
<span className="file-name">{bootFile? bootFile.name:""}</span>
Expand Down
32 changes: 32 additions & 0 deletions webusb/src/components/Decompress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect, useState } from "react"
import useDecompress from '../logic/useDecompress'
import { DATA_SZ, BLK_SZ, PACKET_SZ } from "../helper/sparse";

const Decompress = () => {
const [flashFile, setFlashFile] = useState();
const [{
requestUSBDevice,
USBDevice,
preBoot,
send_chunk_headers,
send_packet,
send_flash,
decompressFileToTransform,
}] = useDecompress(flashFile);

useEffect(()=> {
console.log(ZstdCodec)
console.log(window.binding);
}, [])

return (
<div>
file to decompress:
<input type="file" onChange={(e) => setFlashFile(e.target.files[0])}/>

<button onClick={requestUSBDevice}>Pair USBDevice </button>
</div>
)
}

export default Decompress
1 change: 1 addition & 0 deletions webusb/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
// import * as Z from 'zstd-codec'

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
Expand Down
Loading

0 comments on commit 15d2b96

Please sign in to comment.