{"id":16476400,"url":"https://github.com/softprops/base64","last_synced_at":"2025-03-23T11:32:58.477Z","repository":{"id":9680895,"uuid":"11625305","full_name":"softprops/base64","owner":"softprops","description":"the 64th base of rfc4648","archived":false,"fork":false,"pushed_at":"2019-02-28T20:54:47.000Z","size":63,"stargazers_count":21,"open_issues_count":3,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-17T11:59:49.369Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softprops.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-24T03:24:17.000Z","updated_at":"2018-09-04T13:57:51.000Z","dependencies_parsed_at":"2022-08-24T13:46:13.910Z","dependency_job_id":null,"html_url":"https://github.com/softprops/base64","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fbase64","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fbase64/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fbase64/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fbase64/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softprops","download_url":"https://codeload.github.com/softprops/base64/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245097158,"owners_count":20560311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T12:42:22.331Z","updated_at":"2025-03-23T11:32:58.139Z","avatar_url":"https://github.com/softprops.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# base64\n\n[![Build Status](https://travis-ci.org/softprops/base64.svg)](https://travis-ci.org/softprops/base64)\n\n\u003e the 64th base of rfc4648\n\nThis is a library for base64 encoding and decoding raw data.\n\n## Install\n\nVia the copy and paste method\n\n```scala\nresolvers += \"softprops-maven\" at \"http://dl.bintray.com/content/softprops/maven\"\n\nlibraryDependencies += \"me.lessis\" %% \"base64\" % \"0.2.0\"\n```\n\nVia [a more civilized method](https://github.com/softprops/ls#readme) which will do the same without all the manual work.\n\n    \u003e ls-install base64\n            \n_Note_ If you are a [bintray-sbt](https://github.com/softprops/bintray-sbt#readme) user you can optionally specify the resolver as\n                        \n```scala\nresolvers += bintray.Opts.resolver.repo(\"softprops\", \"maven\")\n```\n\n## Usage\n\nThis library encodes and decodes Byte Arrays but exposes a [typeclass interface](https://github.com/softprops/base64/blob/master/src/main/scala/input.scala#L8-L10) for providing input defined as \n\n```scala\ntrait Input[T] {\n  def bytes: Array[Byte]\n}\n```\n\nInstances of this typeclass are defined for `java.nio.ByteBuffer`, `String`, `(String, java.nio.charset.Charset)`, and\n`Array[Bytes]`. \n\n### Standard Encoding\n\nTo base64 encode input simply invoke the `Encode` objects `apply` method\n\n```scala\nbase64.Encode(\"Man\") \n```\n\nThis returns a Byte Array. To make this output human readable, you may wish to create a String from its output.\n\n### URL-Safe Encoding\n\nWhen working with web applications its a common need to base64 encode information in a urlsafe way. Do do so with this library\njust invoke `urlSafe` with input on the `Encode` object\n\n```scala\nnew String(base64.Encode.urlSafe(\"hello world?\")) // aGVsbG8gd29ybGQ_\n```\n\n### Multiline Encoding\n\nFixing the width of base64 encoded data is, in some cases, a desireble property. In these cases, set the `multiline` flag to true when encoding.\n\n```scala\nval in = \"Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.\"\n\nnew String(base64.Encode(in, multiline = true))\n```\n\nwill produce \n\n```\nQmFzZTY0IGlzIGEgZ3JvdXAgb2Ygc2ltaWxhciBiaW5hcnktdG8tdGV4dCBlbmNvZGluZyBzY2hl\nbWVzIHRoYXQgcmVwcmVzZW50IGJpbmFyeSBkYXRhIGluIGFuIEFTQ0lJIHN0cmluZyBmb3JtYXQg\nYnkgdHJhbnNsYXRpbmcgaXQgaW50byBhIHJhZGl4LTY0IHJlcHJlc2VudGF0aW9uLiBUaGUgdGVy\nbSBCYXNlNjQgb3JpZ2luYXRlcyBmcm9tIGEgc3BlY2lmaWMgTUlNRSBjb250ZW50IHRyYW5zZmVy\nIGVuY29kaW5nLg==\n```\n\n### Omitting padding\n\nYou can omit padding from the output of encodings by setting `pad` option to false\n\nThis will have the following effect on the results\n\n\nWith padding\n\n```scala\nnew String(base64.Encode(\"paddington\")) // cGFkZGluZ3Rvbg==\n```\n\nWithout padding\n\n```scala\nnew String(base64.Encode(\"paddington\", pad = false)) // cGFkZGluZ3Rvbg\n```\n\n### Decoding\n\nA dual for each is provided with the `Decode` object.\n\n```scala\nnew String(base64.Decode.urlSafe(base64.Encode.urlSafe(\"hello world?\"))) // hello world?\n```\n\n## Why\n\nChances are you probably need a base64 codec.\n\nChances are you probably don't need everything that came with the library you use to base64 encode data.\n\nThis library aims to only do one thing. base64 _. That's it.\n\nA seconday goal was to fully understand [rfc4648](http://www.ietf.org/rfc/rfc4648.txt) from first principals. Implementation is a good learning tool. You should try it.\n\n## Performance\n\nPerformance really depends on your usecase, _no matter library you use_. An attempt was made to compare\nthe encoding and decoding performance with the same input data against apache commons-codec base64 and\nnetty 4.0.7.final base64.\n\nFor encoding and decoding I found the following general repeating performance patterns\nwhen testing [15,000 runs](https://github.com/softprops/base64/blob/master/src/test/scala/base64/bench.scala#L53) for each library for each operation.\n\n```\nenc apache commons (byte arrays) took 97 ms\nenc netty (byte buf)             took 95 ms\nenc ours (byte arrays)           took 121 ms\ndec apache commons (byte arrays) took 77 ms\ndec netty (byte buf)             took 171 ms\ndec ours (byte arrays)           took 85 ms\n```\n\nTake this with a grain of salt. None of these will be the performance bottle neck of your application. This was\njust a simple measurement test to make sure this library was not doing something totally naive.\n\n### inspiration and learning\n\ntaken from\n\n* [Robert Harder's public domain](http://iharder.sourceforge.net/current/java/base64/)\n* [netty base64](https://github.com/netty/netty/tree/master/codec/src/main/java/io/netty/handler/codec/base64)\n* [haskell base64](https://github.com/bos/base64-bytestring/tree/master/Data/ByteString)\n* [@tototoshi](https://github.com/tototoshi/scala-base64)\n\nDoug Tangren (softprops) 2013-2014\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftprops%2Fbase64","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftprops%2Fbase64","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftprops%2Fbase64/lists"}