You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've just worked on the ya-webadb based sideload feature and want to share it. Maybe someone finds the time to create a proper PR - I still stuggle a bit with the huge repo :D
constADB_EXIT_SUCCESS='DONEDONE'constADB_EXIT_FAILURE='FAILFAIL'constADB_SIDELOAD_CHUNK_SIZE=65536asyncfunctionadbSideload(device: Adb,data: Blob,onProgress: (percentage: number)=>void=(_)=>{}){constsocket=awaitdevice.createSocket(`sideload-host:${data.size}:${ADB_SIDELOAD_CHUNK_SIZE}`)constreader=socket.readable.getReader()constwriter=socket.writable.getWriter()try{lettransmittedBytes=0while(true){constres=awaitreader.read()if(res.done){thrownewError('reader unexpectedly ended')}constresStr=Buffer.from(res.value).toString('ascii')if(resStr==ADB_EXIT_SUCCESS){break}elseif(resStr==ADB_EXIT_FAILURE){thrownewError('sideload failed')}constrequestedBlock=parseInt(resStr)constoffset=requestedBlock*ADB_SIDELOAD_CHUNK_SIZE;if(offset>data.size){thrownewError(`"adb: failed to read block ${requestedBlock} at offset ${offset}, past end ${data.size}`)}constend=Math.min(offset+ADB_SIDELOAD_CHUNK_SIZE,data.size)constchunk=data.slice(offset,end)awaitwriter.write(newUint8Array(awaitchunk.arrayBuffer()))transmittedBytes+=chunk.sizeonProgress(transmittedBytes/data.size*100*0.99)}}catch(err){awaitsocket.close().catch(()=>{})throwerr}awaitsocket.close()}
#edit: I've used Buffer to convert the Uint8Array to a string, which is not available in the browser. this should be therefore replaced with something cross-platform compatible
Add support to sideload a rom, but say not recommend as it is really fragile and this isn't really stable.
The text was updated successfully, but these errors were encountered: