strm.next_in = c_in;
do {
- strm.avail_out = max_len;
bufferptr ptr = buffer::create_page_aligned(max_len);
strm.next_out = (unsigned char*)ptr.c_str() + begin;
+ strm.avail_out = max_len - begin;
if (begin) {
ptr.c_str()[0] = 0;
begin = 0;
strm.next_in = c_in;
do {
- strm.avail_out = max_len;
bufferptr ptr = buffer::create_page_aligned(max_len);
strm.next_out = (unsigned char*)ptr.c_str() + begin;
+ strm.avail_out = max_len - begin;
if (begin) {
ptr.c_str()[0] = 1;
begin = 0;
}
size_t remaining = MIN(p.get_remaining(), compressed_size);
- while(remaining) {
+ while(remaining) {
long unsigned int len = p.get_ptr_and_advance(remaining, &c_in);
remaining -= len;
- strm.avail_in = len;
+ strm.avail_in = len - begin;
strm.next_in = (unsigned char*)c_in + begin;
begin = 0;
have = max_len - strm.avail_out;
out.append(ptr, 0, have);
} while (strm.avail_out == 0);
-
}
/* clean up and return */
ZlibCompressor sp(false);
EXPECT_STREQ(sp.get_type().c_str(), "zlib");
const char* test = "This is test text";
+ int res;
int len = strlen(test);
bufferlist in, out;
+ bufferlist after;
+ bufferlist exp;
in.append(test, len);
- int res = sp.compress(in, out);
+ res = sp.compress(in, out);
EXPECT_EQ(res, 0);
- bufferlist after;
res = sp.decompress(out, after);
EXPECT_EQ(res, 0);
- bufferlist exp;
exp.append(test);
EXPECT_TRUE(exp.contents_equal(after));
after.clear();
res = sp.decompress(it, compressed_len, after);
EXPECT_EQ(res, 0);
EXPECT_TRUE(exp.contents_equal(after));
+
+ //large block and non-begin iterator for continuous block
+ std::string data;
+ data.resize(0x10000 * 1);
+ for(size_t i = 0; i < data.size(); i++)
+ data[i] = i / 256;
+ in.clear();
+ out.clear();
+ in.append(data);
+ exp = in;
+ res = sp.compress(in, out);
+ EXPECT_EQ(res, 0);
+ compressed_len = out.length();
+ out.append_zero(0x10000 - out.length());
+ after.clear();
+ out.c_str();
+ bufferlist prefix;
+ prefix.append(string("some prefix"));
+ size_t prefix_len = prefix.length();
+ out.claim_prepend(prefix);
+ it = out.begin();
+ it.advance(prefix_len);
+ res = sp.decompress(it, compressed_len, after);
+ EXPECT_EQ(res, 0);
+ EXPECT_TRUE(exp.contents_equal(after));
}
TEST(ZlibCompressor, compress_decompress_chunk)
bufferlist exp;
exp.append("This is test text1234567890");
EXPECT_TRUE(exp.contents_equal(after));
+
+
}
TEST(ZlibCompressor, compress_decompress_isal)
EXPECT_TRUE(exp.contents_equal(after));
}
-
int main(int argc, char **argv) {
vector<const char*> args;
argv_to_vec(argc, (const char **)argv, args);