adding gzip/replaced bad base64 impl with libgdx's

This commit is contained in:
minjaesong
2020-10-20 17:44:59 +09:00
parent ca672f23c2
commit f49cb6c300
9 changed files with 239 additions and 210 deletions

View File

@@ -0,0 +1,17 @@
package net.torvald.tsvm
import com.badlogic.gdx.utils.Base64Coder
class Base64Delegate {
fun atob(inputstr: String): ByteArray {
return Base64Coder.decode(inputstr)
}
fun btoa(inputbytes: ByteArray): String {
val sb = StringBuilder()
sb.append(Base64Coder.encode(inputbytes))
return sb.toString()
}
}

View File

@@ -0,0 +1,41 @@
package net.torvald.tsvm
import com.badlogic.gdx.utils.compression.Lzma
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
class CompressorDelegate {
/*fun comp(ba: ByteArray): ByteArray {
val bin = ByteArrayInputStream(ba)
val bout = ByteArrayOutputStream(256)
Lzma.compress(bin, bout)
return bout.toByteArray()
}
fun decomp(ba: ByteArray): ByteArray {
val bin = ByteArrayInputStream(ba)
val bout = ByteArrayOutputStream(256)
Lzma.decompress(bin, bout)
return bout.toByteArray()
}*/
fun comp(ba: ByteArray): ByteArray {
val baos = ByteArrayOutputStream()
val gz = GZIPOutputStream(baos)
gz.write(ba); gz.flush(); gz.finish()
baos.flush(); baos.close()
return baos.toByteArray()
}
fun decomp(ba: ByteArray): ByteArray {
val bais = ByteArrayInputStream(ba)
val gz = GZIPInputStream(bais)
val ret = gz.readBytes()
gz.close(); bais.close()
return ret
}
}

View File

@@ -65,6 +65,7 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
//val fr = FileReader("./assets/tvdos/command.js")
//val fr = FileReader("./assets/zippytest.js")
val fr = FileReader("./assets/tvdos/fsh.js")
//val fr = FileReader("./assets/tbas/basic.js")
//val fr = FileReader("./assets/jscon.js")

View File

@@ -76,9 +76,9 @@ object VMRunnerFactory {
init {
bind.put("sys", VMJSR223Delegate(vm)) // TODO use delegator class to access peripheral (do not expose VM itself)
bind.put("graphics", GraphicsJSR223Delegate(vm))
//bind.put("poke", { a: Long, b: Byte -> vm.poke(a, b) }) // kts: lambda does not work...
//bind.put("nanotime", { System.nanoTime() })
bind.put("serial", VMSerialDebugger(vm))
bind.put("gzip", CompressorDelegate())
bind.put("base64", Base64Delegate())
if (extension == "js") {
val fr = FileReader("./assets/JS_INIT.js")