* 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)
| 19 | * @return {(Integer|undefined)} - size of the part or undefined |
| 20 | */ |
| 21 | function 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 |