A bytes file of exactly 64 KiB stays inline: take its exact decoded length (issue 1694)
mesh/merge-gate head 6c857e1c025f merged into trunk b68fc755894c — pass, with a note: builds mesh-sdk (+41 dependent(s)) → ace, g14, novox, shanks; no bus …
mesh/repo-check head 6c857e1c025f merged into trunk b68fc755894c — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (typescript)…
mesh/delivery delivering: 0 machine step(s) passed
mesh/merge-gate head 6c857e1c025f merged into trunk b68fc755894c — pass, with a note: builds mesh-sdk (+41 dependent(s)) → ace, g14, novox, shanks; no bus …
mesh/repo-check head 6c857e1c025f merged into trunk b68fc755894c — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (typescript)…
mesh/delivery delivering: 0 machine step(s) passed
This commit is contained in:
@@ -85,7 +85,9 @@ func (f *File) TravelsByDigest() bool {
|
||||
return false
|
||||
}
|
||||
if f.Bytes != "" {
|
||||
return base64.StdEncoding.DecodedLen(len(f.Bytes)) > FileReferenceThreshold
|
||||
// DecodedLen counts padding, so the exact length is taken off the decoded bytes.
|
||||
body, err := f.Body()
|
||||
return err == nil && len(body) > FileReferenceThreshold
|
||||
}
|
||||
return len(f.Content) > FileReferenceThreshold
|
||||
}
|
||||
|
||||
@@ -111,6 +111,13 @@ func TestWhichFilesTravelByDigest(t *testing.T) {
|
||||
t.Errorf("%s was made a reference", name)
|
||||
}
|
||||
}
|
||||
exact := File{ID: "m.e", Bytes: base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{7}, FileReferenceThreshold))}
|
||||
if exact.TravelsByDigest() {
|
||||
t.Error("a bytes file of exactly the threshold travels by digest")
|
||||
}
|
||||
if _, _, err := exact.AsReference(); err == nil {
|
||||
t.Error("a bytes file of exactly the threshold was made a reference")
|
||||
}
|
||||
raw := bytes.Repeat([]byte{0, 1, 2}, FileReferenceThreshold)
|
||||
f := File{ID: "m.b", Bytes: base64.StdEncoding.EncodeToString(raw)}
|
||||
ref, body, err := f.AsReference()
|
||||
|
||||
Reference in New Issue
Block a user