Skip to content
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

Base64 decoding/encoding source/sink #613

Open
MartinDevi opened this issue May 22, 2019 · 2 comments · May be fixed by #819
Open

Base64 decoding/encoding source/sink #613

MartinDevi opened this issue May 22, 2019 · 2 comments · May be fixed by #819
Milestone

Comments

@MartinDevi
Copy link
Contributor

MartinDevi commented May 22, 2019

class Base64Decoder(private val reader: Reader): Source
class Base64Encoder(private val writer: Writer): Sink

Has this feature been considered before? I'd happily put some time in to work on it.

In the suggestion above, I use the Reader/Writer classes because since Base64 uses text characters it seems to make more sense.

@swankjesse
Copy link
Member

You should avoid situations that require streaming base64. The ByteString encoder/decoder should be enough for most use cases.

That said, I'd love to see a gist that does this. In those awkward cases where you have a lot of base64 this could be handy.

@MartinDevi
Copy link
Contributor Author

If only I had the luxury of choosing the format of the data that I receive 😄

I gave it a shot for the Base64Decoder. I would've preferred to have this within the Okio library itself though, rather than having to copy the Base64 decoder into my own project.

Base64Decoder.kt

All that's needed is some specific Base64 methods which don't perform string allocations. Should be fairly easy to add.

fun CharArray.decodeBase64(target: ByteArray, offset: Int, length: Int)
fun CharArray.decodeBase64(target: Buffer, offset: Int, length: Int)

@MartinDevi MartinDevi linked a pull request Nov 18, 2020 that will close this issue
@swankjesse swankjesse added this to the Backlog milestone Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants