added buffer.base64std
This commit is contained in:
parent
d0d79d2f07
commit
368ce2ce8c
@ -120,17 +120,18 @@ which is used in `toString`) and hex encoding:
|
||||
|
||||
## Members
|
||||
|
||||
| name | meaning | type |
|
||||
|----------------------------|-----------------------------------------|---------------|
|
||||
| `size` | size | Int |
|
||||
| `decodeUtf8` | decode to String using UTF8 rules | Any |
|
||||
| `+` | buffer concatenation | Any |
|
||||
| `toMutable()` | create a mutable copy | MutableBuffer |
|
||||
| `hex` | encode to hex strign | String |
|
||||
| `Buffer.decodeHex(hexStr) | decode hex string | Buffer |
|
||||
| `base64` | encode to base64 (url flavor) (2) | String |
|
||||
| `Buffer.decodeBase64(str)` | decode base64 to new Buffer (2) | Buffer |
|
||||
| `toBitInput()` | create bit input from a byte buffer (3) | |
|
||||
| name | meaning | type |
|
||||
|----------------------------|------------------------------------------------|---------------|
|
||||
| `size` | size | Int |
|
||||
| `decodeUtf8` | decode to String using UTF8 rules | Any |
|
||||
| `+` | buffer concatenation | Any |
|
||||
| `toMutable()` | create a mutable copy | MutableBuffer |
|
||||
| `hex` | encode to hex strign | String |
|
||||
| `Buffer.decodeHex(hexStr) | decode hex string | Buffer |
|
||||
| `base64` | encode to base64 (url flavor) (2) | String |
|
||||
| `base64std` | encode to base64 (default vocabulary, filling) | String |
|
||||
| `Buffer.decodeBase64(str)` | decode base64 to new Buffer (2) | Buffer |
|
||||
| `toBitInput()` | create bit input from a byte buffer (3) | |
|
||||
|
||||
(1)
|
||||
: optimized implementation that override `Iterable` one
|
||||
|
||||
@ -30,6 +30,7 @@ import net.sergeych.lynon.LynonDecoder
|
||||
import net.sergeych.lynon.LynonEncoder
|
||||
import net.sergeych.lynon.LynonType
|
||||
import net.sergeych.mp_tools.decodeBase64Url
|
||||
import net.sergeych.mp_tools.encodeToBase64
|
||||
import net.sergeych.mp_tools.encodeToBase64Url
|
||||
import kotlin.math.min
|
||||
|
||||
@ -39,6 +40,7 @@ open class ObjBuffer(val byteArray: UByteArray) : Obj() {
|
||||
|
||||
val hex by lazy { byteArray.encodeToHex("")}
|
||||
val base64 by lazy { byteArray.toByteArray().encodeToBase64Url()}
|
||||
val base64std by lazy { byteArray.toByteArray().encodeToBase64()}
|
||||
|
||||
fun checkIndex(scope: Scope, index: Obj): Int {
|
||||
if (index !is ObjInt)
|
||||
@ -196,6 +198,13 @@ open class ObjBuffer(val byteArray: UByteArray) : Obj() {
|
||||
moduleName = "lyng.stdlib",
|
||||
getter = { thisAs<ObjBuffer>().base64.toObj() }
|
||||
)
|
||||
addPropertyDoc(
|
||||
name = "base64std",
|
||||
doc = "Base64 standard string representation of the buffer.",
|
||||
type = type("lyng.String"),
|
||||
moduleName = "lyng.stdlib",
|
||||
getter = { thisAs<ObjBuffer>().base64std.toObj() }
|
||||
)
|
||||
addFn("decodeUtf8") {
|
||||
ObjString(
|
||||
thisAs<ObjBuffer>().byteArray.toByteArray().decodeToString()
|
||||
|
||||
@ -3233,6 +3233,7 @@ class ScriptTest {
|
||||
assertEquals( "hello", b.decodeUtf8() )
|
||||
|
||||
println(b.base64)
|
||||
println(b.base64std)
|
||||
println(b.hex)
|
||||
|
||||
assertEquals( b, Buffer.decodeBase64(b.base64) )
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user