Expand description
Decode a combined mode encoding to an output slice. The slice must be at least the length
reported by parse_and_check_content_len
. This returns the number of decoded bytes if
successful, or an error if the encoding doesn’t match the hash
.
If the std
feature is enabled, as it is by default, this will use multiple threads via Rayon.
Example
let input = b"foobar";
let (hash, encoded) = bao::encode::encode_to_vec(input);
// Note that if you're allocating a new Vec like this, decode_to_vec is more convenient.
let mut output = vec![0; input.len()];
let content_len = bao::decode::decode(&encoded, &mut output, &hash).unwrap();
assert_eq!(input.len(), content_len);
assert_eq!(input, &output[..content_len]);