MCPcopy Index your code
hub / github.com/scality/cloudserver / getPartSize

Function getPartSize

lib/api/apiUtils/object/partInfo.js:21–55  ·  view source on GitHub ↗

* Gets the size of the requested part of the object * @param {object} objMD - object metadata * @param {object} partNumber - part number * @return {(Integer|undefined)} - size of the part or undefined

(objMD, partNumber)

Source from the content-addressed store, hash-verified

19 * @return {(Integer|undefined)} - size of the part or undefined
20 */
21function getPartSize(objMD, partNumber) {
22 let size;
23 let locationPartNumber;
24 if (partNumber && objMD && objMD.location
25 && objMD.location.length >= partNumber) {
26 const locations = [];
27 for (let i = 0; i < objMD.location.length; i++) {
28 const { dataStoreETag } = objMD.location[i];
29 if (dataStoreETag) {
30 locationPartNumber =
31 Number.parseInt(dataStoreETag.split(':')[0], 10);
32 } else {
33 /**
34 * Location objects prior to GA7.1 do not include the
35 * dataStoreETag field so we cannot find the part range,
36 * the objects are treated as if they only have 1 part
37 */
38 locationPartNumber = 1;
39 }
40 // Get all parts that belong to the requested part number
41 if (partNumber === locationPartNumber) {
42 locations.push(objMD.location[i]);
43 } else if (locationPartNumber > partNumber) {
44 break;
45 }
46 }
47 if (locations.length > 0) {
48 const { start } = locations[0];
49 const endLocation = locations[locations.length - 1];
50 const end = endLocation.start + endLocation.size - 1;
51 size = end - start + 1;
52 }
53 }
54 return size;
55}
56
57/**
58 * Gets parts count if object was put with mpu

Callers 1

objectHeadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected