-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider structures other than Array[Byte]
#8
Comments
@bblfish How does this look? scala> import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.ArrayBuffer
scala> val a= ArrayBuffer[Byte]() ++ "abc".getBytes
a: scala.collection.mutable.ArrayBuffer[Byte] = ArrayBuffer(97, 98, 99)
scala> a.toBase64
res0: String = YWJj It works on a |
That probably helps in many situations. But I don't know if it helps with We were discussing this today on the scala-js gitter. |
The latest commit (and I published it to bintray) supports a java.nio.ByteBuffer has an |
yes, no need to support ArrayBuffer as that is a JS view on something that is very similar to I can try the |
This is my current code import com.github.marklister.base64.Base64._
val bb = TypedArrayBuffer.wrap(sig.asInstanceOf[ArrayBuffer])
val arraybuf: Array[Byte] = new Array[Byte](bb.remaining())
bb.get(arraybuf)
val hashedSig = arraybuf.toBase64
bb.toBase64 Then later when you have time you could optimise away the copy. |
So would
not work? |
Well that would make it a pure scala-js function. |
Ah! I see! I had it confused with |
my fault. Should have included the imports. Sorry! |
Got my code working! I had a bug on the server with encoding/decoding BigIntegers from hexadecimal. read-write-web/rww-play@de8655e |
Yeah, I bumped into this same problem a few years ago. See my basen lib. |
From #6 (@bblfish)
Perhaps there is an extra improvement you can add. Is it possible to abstract somewhat from an array? For example the JS seems to return a ArrayBuffer which I think can be turned into a java.nio.ByteBuffer using TypedArrayBufferBridge.
So it would be useful to have a method that could work with those elements and not just arrays. I am not yet quite sure what the best abstraction here would be... Certainly given that you don't need to change the source object, an Array is too precise.
There is some example code here using a ByteBuffer https://gist.github.com/mseddon/1cfcb0970272cac40497
The text was updated successfully, but these errors were encountered: