rc.setReadAheadBytes(ctx.getOptions().getStreamPackBufferSize());
long position = 12;
long remaining = length - (12 + 20);
+ boolean packHeadSkipped = false;
while (0 < remaining) {
DfsBlock b = cache.get(key, alignToBlock(position));
if (b != null) {
position += n;
remaining -= n;
rc.position(position);
+ packHeadSkipped = true;
continue;
}
throw packfileIsTruncated();
else if (n > remaining)
n = (int) remaining;
- out.write(buf.array(), 0, n);
+
+ if (!packHeadSkipped) {
+ // Need skip the 'PACK' header for the first read
+ out.write(buf.array(), 12, n - 12);
+ packHeadSkipped = true;
+ } else {
+ out.write(buf.array(), 0, n);
+ }
position += n;
remaining -= n;
}