marklister / base64 Goto Github PK
View Code? Open in Web Editor NEWTiny scala-js compatible base64 encoder/decoder written in idiomatic scala. Available on Maven central.
License: BSD 2-Clause "Simplified" License
Tiny scala-js compatible base64 encoder/decoder written in idiomatic scala. Available on Maven central.
License: BSD 2-Clause "Simplified" License
Lib began as a concise functional and very inefficient look at Base64. Since scala-js it's probably necessary to improve speed and reduce garbage production.
General approach will be to use some mutable data structures and direct array referencing.
Decode would be probably faster if you premake lettercode-to-number array, instead of using indexOf on number-to-letter array.
Could be replaced by a fold or something.
Hey, I compiled it to javascript using scala-js and if you do something like :
href = "data:application/octet-stream;base64," + data.stripMargin.getBytes.toBase64
Then the downloaded file ends with some incorrectly decoded characters, otherwise it is alright. So I suspect that the Webkit/Chrome decoding is not compatible with this base64 encoding...
Btw to make this scala-js compatible one just need to comment out the specs2 test suite (that doesn't compile to javascript) or rewrite it using some scala-js compliant testing framework like utest and add plugin :
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0-M3")
and enable it :
lazy val base64 = (project in file(".")).enablePlugins(org.scalajs.sbtplugin.ScalaJSPlugin)
Hi @marklister
I was wondering whether you could release a new version against the latest scalajs? It's actually luckily humming along if it weren't for those big upgrades :-)
Thanks a lot,
Tanju
String Concat is a bad idea.
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
When coding a query parameter to base64, the padding =
s make it invalid. Some other URI compatible character should be used instead.
See #6
JS WebCrytpoAPI produces Base64URL encoded strings in jws
mode.
See the code here to produce those
http://stackoverflow.com/questions/33642310/is-there-a-way-to-get-the-components-of-an-rsa-key-in-the-webcrypto-api
The following JS code does the trick to convert it
function encodeURL(str){
return str.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');
}
function decodeUrl(str){
str = (str + '===').slice(0, str.length + (str.length % 4));
return str.replace(/-/g, '+').replace(/_/g, '/');
}
and then one can use window.atob
I tried the library here, but it gives an error
Thing to consider. There are more than one standards of base64. base64url, for example, is increasingly popular, because it makes embedding it in urls easier.
You may want to add support for base64url to your lib, unless you consider it too much bloat.
Hi @marklister
Thanks for this little compact library! However, I noticed that jars don't contain any class/sjs files. 0.2.4 worked like a charm.
http://central.maven.org/maven2/com/github/marklister/base64_sjs0.6_2.12/0.2.5/base64_sjs0.6_2.12-0.2.5.jar
http://central.maven.org/maven2/com/github/marklister/base64_2.12/0.2.5/base64_2.12-0.2.5.jar
I could find only 0.1.1 from Maven Central, nothing more recent than that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.