Beispiel #1
0
cl_byte64 CL_ZipReader_Impl::deflate_read(void *data, cl_byte64 size, bool read_all)
{
	zs.next_out = (Bytef *) data;
	zs.avail_out = size;
	// Continue feeding zlib data until we get our data:
	while (zs.avail_out > 0)
	{
		// zlib needs more data:
		if (zs.avail_in == 0 && compressed_pos < local_header.compressed_size)
		{
			// Read some compressed data:
			int received_input = 0;
			while (received_input < 16*1024)
			{
				received_input += input.receive(zbuffer, int(cl_min(16*1024, local_header.compressed_size - compressed_pos)), true);
				if (compressed_pos + received_input == local_header.compressed_size) break;
			}
			compressed_pos += received_input;

			zs.next_in = (Bytef *) zbuffer;
			zs.avail_in = received_input;
		}

		// Decompress data:
		int result = inflate(&zs, (compressed_pos == local_header.compressed_size) ? Z_FINISH : Z_NO_FLUSH);
		if (result == Z_STREAM_END) break;
		if (result == Z_NEED_DICT) throw CL_Exception("Zlib inflate wants a dictionary!");
		if (result == Z_DATA_ERROR) throw CL_Exception("Zip data stream is corrupted");
		if (result == Z_STREAM_ERROR) throw CL_Exception("Zip stream structure was inconsistent!");
		if (result == Z_MEM_ERROR) throw CL_Exception("Zlib did not have enough memory to decompress file!");
		if (result == Z_BUF_ERROR) throw CL_Exception("Not enough data in buffer when Z_FINISH was used");
		if (result != Z_OK) throw CL_Exception("Zlib inflate failed while decompressing zip file!");
	}
	return size - zs.avail_out;
}
Beispiel #2
0
CL_XMLTokenizer::CL_XMLTokenizer(CL_IODevice &input) : impl(new CL_XMLTokenizer_Generic)
{
	impl->input = input;
	impl->size = input.get_size();
	impl->pos = 0;

	CL_DataBuffer buffer(impl->size);
	input.receive(buffer.get_data(), buffer.get_size(), true);

	CL_StringHelp::BOMType bom_type = CL_StringHelp::detect_bom(buffer.get_data(), buffer.get_size());
	switch (bom_type)
	{
	default:
	case CL_StringHelp::bom_none:
		impl->data = CL_StringHelp::utf8_to_text(CL_StringRef8(buffer.get_data(), buffer.get_size(), false));
		break;
	case CL_StringHelp::bom_utf32_be:
	case CL_StringHelp::bom_utf32_le:
		throw CL_Exception("UTF-16 XML files not supported yet");
		break;
	case CL_StringHelp::bom_utf16_be:
	case CL_StringHelp::bom_utf16_le:
		throw CL_Exception("UTF-32 XML files not supported yet");
		break;
	case CL_StringHelp::bom_utf8:
		impl->data = CL_StringHelp::utf8_to_text(CL_StringRef8(buffer.get_data()+3, buffer.get_size()-3, false));
		break;
	}

}