Compare commits

..

1 Commits

Author SHA1 Message Date
Daniel Martí
8f4ec9e084 implement CidFromReader
And reuse two CidFromBytes tests for it, which includes both CIDv0 and
CIDv1 cases as inputs, as well as some inputs that should error.

Fixes #126.
2021-07-14 23:28:25 +01:00
2 changed files with 1 additions and 2 deletions

2
cid.go
View File

@@ -793,7 +793,7 @@ func CidFromReader(r io.Reader) (int, Cid, error) {
if cidLength > cap(br.dst) { if cidLength > cap(br.dst) {
// If the multihash digest doesn't fit in our initial 64 bytes, // If the multihash digest doesn't fit in our initial 64 bytes,
// efficiently extend the slice via append+make. // efficiently extend the slice via append+make.
br.dst = append(br.dst, make([]byte, cidLength-len(br.dst))...) br.dst = append(br.dst, make([]byte, cidLength-cap(br.dst))...)
} else { } else {
// The multihash digest fits inside our buffer, // The multihash digest fits inside our buffer,
// so just extend its capacity. // so just extend its capacity.

View File

@@ -667,7 +667,6 @@ func TestReadCidsFromBuffer(t *testing.T) {
"k2cwueckqkibutvhkr4p2ln2pjcaxaakpd9db0e7j7ax1lxhhxy3ekpv", "k2cwueckqkibutvhkr4p2ln2pjcaxaakpd9db0e7j7ax1lxhhxy3ekpv",
"Qmf5Qzp6nGBku7CEn2UQx4mgN8TW69YUok36DrGa6NN893", "Qmf5Qzp6nGBku7CEn2UQx4mgN8TW69YUok36DrGa6NN893",
"zb2rhZi1JR4eNc2jBGaRYJKYM8JEB4ovenym8L1CmFsRAytkz", "zb2rhZi1JR4eNc2jBGaRYJKYM8JEB4ovenym8L1CmFsRAytkz",
"bafkqarjpmzuwyzltorxxezjpkvcfgqkfjfbfcvslivje2vchkzdu6rckjjcfgtkolaze6mssjqzeyn2ekrcfatkjku2vowseky3fswkfkm2deqkrju3e2",
} }
var cids []Cid var cids []Cid