-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zstd-codec support for decompressing files #382
Open
sarahfwang
wants to merge
17
commits into
nxp-imx:master
Choose a base branch
from
sarahfwang:nxp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
787880f
cleanup 2 at nxp/master
08b5fd6
webusb: add zstd decompress support for wic image
a4c7c4e
webusb: add zstd decompress support for wic image
65755ae
merge
wwang00 34a07ae
working on this, change later
wwang00 9816f3f
bunch of stuff that doesn't work
e311d62
scuffed, but logic is correct
b4c8df1
can decompress one chunk and do promises in an async callback
wwang00 8ab6186
decompress multiple chunks one after another
wwang00 fffc0d4
Merge branch 'master' of https://github.com/nxp-imx/mfgtools into nxp
d8a3095
todo: flash for board
9fd7296
decompress works
5a5926e
deleted a lot of Decompress copies and notes
33d942b
deleted some lines
9bd2e54
tyring to make it look better
8f7ecce
more pretty demo
880ead2
test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
On branch nxp | ||
Your branch is ahead of 'nxp/master' by 2 commits. | ||
(use "git push" to publish your local commits) | ||
|
||
Changes not staged for commit: | ||
(use "git add <file>..." to update what will be committed) | ||
(use "git restore <file>..." to discard changes in working directory) | ||
modified: webusb/package.json | ||
|
||
Untracked files: | ||
(use "git add <file>..." to include in what will be committed) | ||
d.txt | ||
|
||
no changes added to commit (use "git add" and/or "git commit -a") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
errors you keep running into: | ||
|
||
must init git submodule for zstd | ||
must start the emsdk thing to use emcc in terminal | ||
updating node version to do serve -s build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useEffect, useState } from "react" | ||
// import useDecompress from '../logic/useDecompress' | ||
import useDecompress from '../logic/useDecompress3' | ||
import { DATA_SZ, BLK_SZ, PACKET_SZ } from "../helper/sparse"; | ||
|
||
const DecompressAlt = () => { | ||
const [flashFile, setFlashFile] = useState(); | ||
const [{ | ||
requestUSBDevice | ||
}] = useDecompress(flashFile); | ||
|
||
useEffect(()=> { | ||
console.log(ZstdCodec) | ||
console.log(window.binding); | ||
}, []) | ||
|
||
return ( | ||
<div> | ||
file to decompress (3): | ||
<input type="file" onChange={(e) => setFlashFile(e.target.files[0])}/> | ||
|
||
<button onClick={requestUSBDevice}>Pair USBDevice </button> | ||
</div> | ||
) | ||
} | ||
|
||
export default DecompressAlt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
class ChunkProcessor | ||
{ | ||
#chunk_size | ||
#buffer | ||
#on_chunk | ||
|
||
/** | ||
* This callback is displayed as part of the Requester class. | ||
* @callback dataCallback | ||
* @param {buffer} Uint8Array | ||
*/ | ||
|
||
/** | ||
* @param {number} chunk_size | ||
* @param {dataCallback} on_chunk | ||
*/ | ||
constructor(chunk_size, on_chunk) | ||
{ | ||
this.#buffer = new Uint8Array(); | ||
this.#chunk_size = chunk_size; | ||
this.#on_chunk = on_chunk; | ||
} | ||
|
||
/** | ||
* @param {Uint8Array} new_buffer | ||
*/ | ||
#append_buffer(new_buffer) { | ||
const temp = new Uint8Array(this.#buffer.length + new_buffer.length); | ||
temp.set(this.#buffer, 0); | ||
temp.set(new_buffer, this.#buffer.length); | ||
this.#buffer = temp; | ||
} | ||
|
||
/** | ||
* Adds new data to the buffer, and consumes chunks | ||
* @param {Uint8Array} new_buffer | ||
*/ | ||
async push_data(new_buffer) { | ||
if(this.#buffer.length + new_buffer.length < this.#chunk_size) { | ||
this.#append_buffer(new_buffer); | ||
return; | ||
} | ||
|
||
// process old data | ||
const chunkPadCount = this.#chunk_size - this.#buffer.length; | ||
this.#append_buffer(new_buffer.slice(0, chunkPadCount)); | ||
await this.#on_chunk(this.#buffer); //TODO:: is this await necessary? | ||
|
||
// remove the data already processed | ||
new_buffer = new_buffer.slice(chunkPadCount); | ||
while(true) { | ||
const curr_slice = new_buffer.slice(0, this.#chunk_size); // dont care about OOB, js handles it for us | ||
if(curr_slice.length === this.#chunk_size) { | ||
await this.#on_chunk(curr_slice); //TODO: same with this await? | ||
new_buffer = new_buffer.slice(this.#chunk_size); | ||
} else { | ||
this.#buffer = curr_slice; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* flushes anything currently being buffered | ||
* @param {dataCallback=} callback | ||
*/ | ||
flush(callback) { | ||
if(!callback) { | ||
callback = this.#on_chunk; | ||
} | ||
|
||
callback(this.#buffer); | ||
this.#buffer = new Uint8Array(); | ||
} | ||
|
||
/** | ||
* processes an entire array, including remaining data | ||
* @param {Uint8Array} new_buffer | ||
* @param {dataCallback=} callback | ||
*/ | ||
process_entire_arr(new_buffer, callback) { | ||
this.push_data(new_buffer); | ||
this.flush(callback); | ||
} | ||
} | ||
|
||
export default ChunkProcessor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am little confused here, after you decompress whole data, then trigger read. did you check memory usage here. You can stop here to check how many memory used by browser.