-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: App conversion load sample inputs
- Loading branch information
Showing
2 changed files
with
40 additions
and
6 deletions.
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
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 |
---|---|---|
@@ -1,12 +1,47 @@ | ||
export default async function conversionLoadSampleInputs (model) { | ||
const progressBar = document.querySelector('#conversionInputs sl-progress-bar[name=progress]') | ||
progressBar.value = 0 | ||
progressBar.setAttribute('style', 'display: block-inline;') | ||
progressBar.setAttribute('style', 'display: block;') | ||
|
||
const inputVolumeElement = document.querySelector("#conversionInputs sl-input[name=input-volume]") | ||
|
||
const response = await fetch('/sample-data/AIMIOTestImage.AIM') | ||
const contentLength = +response.headers.get('Content-Length'); | ||
inputVolumeElement.helpText = 'Input volume size: ' + contentLength + ' bytes' | ||
progressBar.max = contentLength | ||
|
||
const reader = response.body.getReader() | ||
|
||
let receivedLength = 0 | ||
const chunks = [] | ||
while(true) { | ||
const {done, value} = await reader.read() | ||
|
||
if (done) { | ||
break | ||
} | ||
|
||
chunks.push(value) | ||
receivedLength += value.length | ||
progressBar.value = receivedLength | ||
progressBar.textContent = `${receivedLength.toString()} / ${contentLength.toString()} bytes` | ||
} | ||
|
||
let inputVolume = new Uint8Array(receivedLength) | ||
let position = 0; | ||
for(let chunk of chunks) { | ||
inputVolume.set(chunk, position); // (4.2) | ||
position += chunk.length; | ||
} | ||
|
||
// const sampleInput = new Uint8Array([222, 173, 190, 239]) | ||
context.inputs.set("input", sampleInput) | ||
const inputElement = document.querySelector("#conversionInputs sl-input[name=input-volume]") | ||
// inputElement.value = sampleInput[:50].toString() + ' ...' | ||
// context.inputs.set("input", sampleInput) | ||
model.inputVolume = inputVolume | ||
inputVolumeElement.value = inputVolume.subarray(0, 50).toString() + ' ...' | ||
progressBar.setAttribute('style', 'display: none;') | ||
progressBar.textContent = '' | ||
progressBar.max = 100 | ||
progressBar.value = 0 | ||
|
||
return model | ||
} |