You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Digest class behaves as a stream writer, so it would make sense to have it inherit IO.
This would allow using Digest implementations as data sink in an IO composition.
For example, in combination with IO::MultiWriter or IO::DupReader (proposed in #14792), it would be trivial to write / read to an IO, while simultaneously calculating a digest of the data.
For example, the following program prints some data to an IO, and calculates the CRC32 on the fly:
Digest even implements << which can be used in a very similar way as in IO. It's not identical, though. Digest#<< is just an alias for #update, while IO#<< implements string concatenation (it calls data.to_s(self), not write(data)).
This would probably be the most difficult problem for integrating Digest with IO, due to the different semantics of #<<.
I don't think there are any other incompatibilities.
The text was updated successfully, but these errors were encountered:
The
Digest
class behaves as a stream writer, so it would make sense to have it inheritIO
.This would allow using
Digest
implementations as data sink in an IO composition.For example, in combination with
IO::MultiWriter
orIO::DupReader
(proposed in #14792), it would be trivial to write / read to an IO, while simultaneously calculating a digest of the data.For example, the following program prints some data to an
IO
, and calculates the CRC32 on the fly:The
Digest#update(data : Bytes)
method is essentially the same asIO#write(slice : Bytes)
, making this similarity very obvious.Digest
even implements<<
which can be used in a very similar way as inIO
. It's not identical, though.Digest#<<
is just an alias for#update
, whileIO#<<
implements string concatenation (it callsdata.to_s(self)
, notwrite(data)
).This would probably be the most difficult problem for integrating
Digest
withIO
, due to the different semantics of#<<
.I don't think there are any other incompatibilities.
The text was updated successfully, but these errors were encountered: