示例#1
0
文件: xcc_z.cpp 项目: 4play/xbt
shared_data xcc_z::gzip(data_ref s)
{
	unsigned long cb_d = s.size() + (s.size() + 999) / 1000 + 12;
	shared_data d(10 + cb_d + 8);
	unsigned char* w = d.data();
	*w++ = 0x1f;
	*w++ = 0x8b;
	*w++ = Z_DEFLATED;
	*w++ = 0;
	*w++ = 0;
	*w++ = 0;
	*w++ = 0;
	*w++ = 0;
	*w++ = 0;
	*w++ = 3;
	{
		z_stream stream;
		stream.zalloc = NULL;
		stream.zfree = NULL;
		stream.opaque = NULL;
		deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
		stream.next_in = const_cast<unsigned char*>(s.begin());
		stream.avail_in = s.size();
		stream.next_out = w;
		stream.avail_out = cb_d;
		deflate(&stream, Z_FINISH);
		deflateEnd(&stream);
		w = stream.next_out;
	}
	w = write_int_le(4, w, crc32(crc32(0, NULL, 0), s.data(), s.size()));
	w = write_int_le(4, w, s.size());
	return d.substr(0, w - d.data());
}
示例#2
0
void Cvirtual_binary::assign(data_ref v)
{
	if (v.size())
	{
		m_source = boost::make_shared<Cvirtual_binary_source>(v.size());
		if (v.begin())
			memcpy(data_edit(), v.data(), v.size());
	}
	else
		m_source.reset();
}
示例#3
0
文件: file32.cpp 项目: ChangerR/xcc
int Cfile32::write(data_ref v)
{
	return write(v.data(), v.size());
};