mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-09 12:41:51 +09:00
adding gzip/replaced bad base64 impl with libgdx's
This commit is contained in:
17
src/net/torvald/tsvm/Base64Delegate.kt
Normal file
17
src/net/torvald/tsvm/Base64Delegate.kt
Normal 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()
|
||||
}
|
||||
|
||||
}
|
||||
41
src/net/torvald/tsvm/CompressorDelegate.kt
Normal file
41
src/net/torvald/tsvm/CompressorDelegate.kt
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user