#include "lib/bucket.h"
#include "lib/lizard.h"
#include "lib/bbuf.h"
+#include "lib/ff-utf8.h"
#include <stdlib.h>
#include <errno.h>
{
while (btell(body) < end && bgets(body, buf, sizeof(buf)))
if (buf[0])
- obj_add_attr(o_hdr, buf[0], buf+1);
+ obj_add_attr(o_body, buf[0], buf+1);
ASSERT(btell(body) == end);
}
}
else if (buck_type == BUCKET_TYPE_V33 || buck_type == BUCKET_TYPE_V33_LIZARD)
{
+ /* Avoid reading the whole bucket if only its header is needed. */
+ if (body_start)
+ {
+ sh_off_t start = btell(body);
+ sh_off_t end = start + buck_len;
+ while (btell(body) < end)
+ {
+ uns len = bget_utf8(body);
+ if (!len)
+ break;
+ byte *buf = mp_alloc_fast_noalign(o_hdr->pool, len);
+ bread(body, buf, len);
+ uns type = buf[--len];
+ buf[len] = 0;
+ obj_add_attr_ref(o_hdr, type, buf);
+ }
+ *body_start = btell(body) - start;
+ return 0;
+ }
+
/* Read all the bucket into 1 buffer, 0-copy if possible. */
byte *ptr, *end;
uns len = bdirect_read_prepare(body, &ptr);
ptr = buf->bb.ptr;
copied = 1;
}
- end = ptr + len;
+ end = ptr + buck_len;
- byte *start = ptr;
ptr = decode_attributes(ptr, end, o_hdr, 0); // header
- if (body_start)
- {
- *body_start = ptr - start;
- if (!copied)
- bdirect_read_commit(body, ptr);
- return 0;
- }
if (buck_type == BUCKET_TYPE_V33_LIZARD) // decompression
{
if (ptr + 8 > end)