Closed jacogr closed 5 years ago
What situation are you in where Buffer
is not equal to Uint8Array
? Node?
@jacogr are you want fix all libraries which you are using? https://github.com/ethereumjs/rlp/pull/16 Why not convert Uint8Array to Buffer before pass it?
From other side, Hash#update allow not only string
/Buffer
. Maybe we should change crypto-browserify libraries... @dcousens ?
The conversion between Uint8Array -> Buffer is a simple one, i.e. Buffer.from(u8a)
. However by skipping this (underlying inside the library the iteration of the data stays the same), it minimises the unneeded allocations that does happen when your are dealing mostly with Uint8Array
(my specific case), i.e. no keccack(Buffer.from(data))
where I'm calling.
So yes, Buffer === Uint8Array (mostly), however Uint8Array !== Buffer (when passed in, needs a conversion).
Additionally, you are correct though, if we are attempting to strictly match Hash#update, the API is a bit wider than currently implemented. (And my PR falls short of expanding that completely)
Allow Uint8Array as input values as well, these can be iterated in the same way inside
absorb
(orupdate
) as theBuffer
.