Since it's planned for `Bytes` to go internal, do ...
# io
k
Since it's planned for
Bytes
to go internal, do we plan to have any equivalent to
ByteString
from okio? Input doesn't seem to entirely fit the bill
a
It seem to do exactly the same as Binary I've introduced in my fork. Base64 encoding could be added on top of it.
k
Yeah, this seems to be a pretty big use case missed. An immutable view into to binary data with helper functions is super useful
I wonder if the io maintainers are interested in including a Binary type in core?
a
We are discussing it. You can try to use my version and report issues and requests here. I think that meaningful discussion will benefit all of us.
k
I do too. Will do, thanks 🙂
a
Base64 and other functionality could be added as extensions. Binary could be
read
from any point and you can create a view of it.
k
That's exactly what I'd want too
Preferably perform a defensive copy on the data on construction
a
It actually does defensive copy. At least in some places
k
Gotcha
a
Not sure that all cases are covered, you need to look into the source code for that.
k
I'll be playing around with it as soon as I get around the that gradle build issue
I will for sure
a
The important thing is that it is optimized for zero-copy reads from files and byte blocks.
k
Okay
This does sort of beg the question....why have a binary type at all? What's the rational for making bytes internal? Couldn't all of the functionality we desire be build on top of bytes as extensions?
a
You can scroll up this chat for previous discussions about that, it should answer your quesion. The problem is that Bytes does not survive beyond the lifetime of input that it is read from. The name is misleading and it was never intended as a binary block.
k
okay, cool
After doing some reading, I would be concerned that binary has the ability to be backed by a file. My ideal would be for this data type to be immutable, which wouldn't be possible with a file. The underlying resource could be mutated and then your view into that is dirtied
a
It depends on a way you open a file. You can lock it for write
k
Would you expect to be able to get a binary view into something like a socket?
a
It is not possible to do a zero-copy view of a socket. But you can currently create a binary from any input. By default it allocates byte array for that.
just use
readBinary
method
k
Interesting, okay