Compare commits

...

1 Commits

Author SHA1 Message Date
alexandremerle cc94a13ebc wip 2017-10-29 18:51:57 +01:00
2 changed files with 40 additions and 3 deletions

View File

@ -4,7 +4,7 @@
* @return {array} parsedLocations - dataLocations filtered for
* what needed and ranges added for particular parts as needed
*/
function setPartRanges(dataLocations, outerRange) {
function setPartRanges(dataLocations, outerRange, log) {
const parsedLocations = [];
if (!outerRange) {
@ -13,6 +13,9 @@ function setPartRanges(dataLocations, outerRange) {
const begin = outerRange[0];
const end = outerRange[1];
if (log) {
log.info('begin set parts', { begin , end });
}
// If have single location, do not need to break up range among parts
// and might not have a start and size property
// on the dataLocation (because might be pre- md-model-version 2),
@ -30,14 +33,20 @@ function setPartRanges(dataLocations, outerRange) {
soleLocation.size =
Math.min(partSize, end - begin + 1).toString();
}
if (log) {
log.info('soleLocation', { soleLocation });
}
parsedLocations.push(soleLocation);
return parsedLocations;
}
// Range is inclusive of endpoint so need plus 1
const max = end - begin + 1;
if (log) {
log.info('multiple locations', { max });
}
let total = 0;
for (let i = 0; i < dataLocations.length; i++) {
if (total >= max) {
if (total >= (max - 1)) {
break;
}
const partStart = parseInt(dataLocations[i].start, 10);
@ -50,6 +59,15 @@ function setPartRanges(dataLocations, outerRange) {
if (partSize + total <= max) {
const partWithoutRange = dataLocations[i];
partWithoutRange.size = partSize.toString();
if (log) {
log.info('add part without range', {
partSize,
total,
max,
partStart,
partWithoutRange,
});
}
parsedLocations.push(partWithoutRange);
total += partSize;
// Otherwise set a range limit on the part end
@ -62,6 +80,15 @@ function setPartRanges(dataLocations, outerRange) {
partWithRange.range = [0, endPart];
// modify size to be stored for object put part copy
partWithRange.size = (endPart + 1).toString();
if (log) {
log.info('add part with range', {
partSize,
total,
max,
partStart,
partWithRange,
});
}
parsedLocations.push(dataLocations[i]);
break;
}
@ -77,6 +104,15 @@ function setPartRanges(dataLocations, outerRange) {
partWithRange.range = [startOffset, endPart];
// modify size to be stored for object put part copy
partWithRange.size = (endPart - startOffset + 1).toString();
if (log) {
log.info('add part with range, second path', {
partSize,
total,
max,
partStart,
partWithRange,
});
}
parsedLocations.push(partWithRange);
// Need to add byte back since with total we are counting
// number of bytes while the endPart and startOffset
@ -84,6 +120,7 @@ function setPartRanges(dataLocations, outerRange) {
total += endPart - startOffset + 1;
}
}
log.info('parsed locations', { parsedLocations });
return parsedLocations;
}

View File

@ -183,7 +183,7 @@ function objectGet(authInfo, request, returnTagCount, log, callback) {
const end = endLocation.start + endLocation.size;
responseMetaHeaders['Content-Length'] = end - start;
const partByteRange = [start, end];
dataLocator = setPartRanges(dataLocator, partByteRange);
dataLocator = setPartRanges(dataLocator, partByteRange, log);
} else {
dataLocator = setPartRanges(dataLocator, byteRange);
}