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
In checking out various checksum algorithms (mostly because I'm messing around with generating checksums), I found that algorithms implemented via the digest crate all have a Write implementation. This can be used as described here to allow for a simple std::io::copy(&mut file, &mut digester) in order to hash what you want - rather than needing to route the data to the algorithm yourself.
However, crc32fast::Hasher has no such Write implementation, so you cannot do the same here. So my suggestion is that a Write implementation be added, so that you can do the same here.
P.S. Admittedly, writing a wrapper for this purpose is easy (see below), but I still think adding a Write impl to crc32fast::Hasher directly would be the better option.
// Note: This wrapper is actually inspired by how the `digest` crate implements// the `Write` trait for use with `std::io::copy()`. In fact, the `Write` impl// is nearly identical when read side-by-side.//// `digest`'s implementation, for comparison:// https://docs.rs/digest/0.10.7/src/digest/core_api/wrapper.rs.html#245-261structCrc32Writer(crc32fast::Hasher);implCrc32Writer{fnfinalize(self) -> u32{self.0.finalize()}}impl std::io::WriteforCrc32Writer{fnwrite(&mutself,buf:&[u8]) -> std::io::Result<usize>{self.0.update(buf);Ok(buf.len())}fnflush(&mutself) -> std::io::Result<()>{Ok(())}}
The text was updated successfully, but these errors were encountered:
Hi!
In checking out various checksum algorithms (mostly because I'm messing around with generating checksums), I found that algorithms implemented via the
digest
crate all have aWrite
implementation. This can be used as described here to allow for a simplestd::io::copy(&mut file, &mut digester)
in order to hash what you want - rather than needing to route the data to the algorithm yourself.However,
crc32fast::Hasher
has no suchWrite
implementation, so you cannot do the same here. So my suggestion is that aWrite
implementation be added, so that you can do the same here.P.S. Admittedly, writing a wrapper for this purpose is easy (see below), but I still think adding a
Write
impl tocrc32fast::Hasher
directly would be the better option.The text was updated successfully, but these errors were encountered: