+ uns lizard_filled = 0;
+ uns in_body = 0;
+ b = NULL;
+ while ((e = bgets(in, buf, sizeof(buf))))
+ {
+ if (!buf[0])
+ {
+ if (in_body || type < BUCKET_TYPE_V30)
+ break;
+ in_body = 1;
+ }
+ if (!b)
+ b = obuck_create(type);
+ if (in_body == 1)
+ {
+ bputc(b, 0);
+ in_body = 2;
+ }
+ else if (type <= BUCKET_TYPE_V33 || !in_body)
+ {
+ bput_attr(b, buf[0], buf+1, e-buf-1);
+ }
+ else
+ {
+ ASSERT(BUCKET_TYPE_V33_LIZARD);
+ uns want_len = lizard_filled + (e-buf) + 6 + LIZARD_NEEDS_CHARS; // +6 is the maximum UTF-8 length
+ bb_grow(&lizard_buf, want_len);
+ byte *ptr = lizard_buf.ptr + lizard_filled;
+ ptr = put_attr(ptr, buf[0], buf+1, e-buf-1);
+ lizard_filled = ptr - lizard_buf.ptr;
+ }
+ }
+ if (in_body && type == BUCKET_TYPE_V33_LIZARD)
+ {
+ bputl(b, lizard_filled
+#if 0 //TEST error resilience: write wrong length
+ +1
+#endif
+ );
+ bputl(b, adler32(lizard_buf.ptr, lizard_filled)
+#if 0 //TEST error resilience: write wrong checksum
+ +1
+#endif
+ );
+ uns want_len = lizard_filled * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD;
+ bb_grow(&compressed_buf, want_len);
+ want_len = lizard_compress(lizard_buf.ptr, lizard_filled, compressed_buf.ptr);
+#if 0 //TEST error resilience: tamper the compressed data by removing EOF
+ compressed_buf[want_len-1] = 1;
+#endif
+ bwrite(b, compressed_buf.ptr, want_len);
+ }
+ if (b)