There's an example in the docs here about creating...
# javascript
t
There's an example in the docs here about creating a Base64 encoder in Kotlin/JS. I was using this in my product, but after upgrading to Kotlin 1.5.0+ it no longer works. The code
js("Buffer")
outputs into the JavaScript console:
Uncaught ReferenceError: Buffer is not defined
https://kotlinlang.org/docs/multiplatform-library.html#js First of all, perhaps that example needs updated? Second, how can I resolve this in my product?
e
just to check ,what do you mean by "JavaScript console"? nodejs's buffer (https://nodejs.org/api/buffer.html) is not implemented in any browser
t
Right, after looking into it earlier I am confused about why it was working before, given that very thing. But it was, in fact, working in my browser, and now it is not. Perhaps something else (I'm using KVision) had a compatible Buffer class? I'm not entirely sure.
I'm happy to replace it with something else, but my JS is very rusty so I'm not entirely sure how to go about base64 encoding in Kotlin/JS
I don't have experience with JS or K/JS either, but this seems to work on playground: https://pl.kotl.in/5B1xGpefV
t
that looks similar to the track I was heading down. I'll try it out here..
it works
thank you
t
window.btoa
+
window.atob
?
e
that is basically what I invoked above, with a wrapper to prepare a kotlin ByteArray into a JS String so that btoa will accept it as input