GetObjectWithValidation has same behavior as GetObject, but performs checksum validation of the object by comparing the checksum in the response header with the calculated checksum value derived from the returned object. Similar to GetObject, if a memory manager/slab allocator is not specified, a t
(baseParams BaseParams, bck cmn.Bck, object string, options ...GetObjectInput)
| 323 | // Returns `cmn.ErrInvalidCksum` when the expected and actual checksum values |
| 324 | // are different. |
| 325 | func GetObjectWithValidation(baseParams BaseParams, bck cmn.Bck, object string, options ...GetObjectInput) (n int64, err error) { |
| 326 | var ( |
| 327 | w = io.Discard |
| 328 | q url.Values |
| 329 | hdr http.Header |
| 330 | ) |
| 331 | if len(options) != 0 { |
| 332 | w, q, hdr = getObjectOptParams(options[0]) |
| 333 | } |
| 334 | baseParams.Method = http.MethodGet |
| 335 | |
| 336 | reqParams := AllocRp() |
| 337 | { |
| 338 | reqParams.BaseParams = baseParams |
| 339 | reqParams.Path = apc.URLPathObjects.Join(bck.Name, object) |
| 340 | reqParams.Query = bck.AddToQuery(q) |
| 341 | reqParams.Header = hdr |
| 342 | reqParams.Validate = true |
| 343 | } |
| 344 | resp, err := reqParams.doResp(w) |
| 345 | FreeRp(reqParams) |
| 346 | if err != nil { |
| 347 | return 0, err |
| 348 | } |
| 349 | hdrCksumValue := resp.Header.Get(apc.HdrObjCksumVal) |
| 350 | if resp.cksumValue != hdrCksumValue { |
| 351 | return 0, cmn.NewErrInvalidCksum(hdrCksumValue, resp.cksumValue) |
| 352 | } |
| 353 | return resp.n, nil |
| 354 | } |
| 355 | |
| 356 | // GetObjectWithResp returns the response and the length of the object. |
| 357 | // It does not validate the checksum of the object in the response. |