Esempio n. 1
0
/// Выводит размеры разжатых и сжатых блоков для сжатого файла.
void stat(DB::ReadBuffer & in, DB::WriteBuffer & out)
{
	while (!in.eof())
	{
		char header[COMPRESSED_BLOCK_HEADER_SIZE];

		in.ignore(16);	/// checksum
		in.readStrict(header, COMPRESSED_BLOCK_HEADER_SIZE);

		size_t size_compressed = 0;
		memcpy(&size_compressed, &header[1], 4);	/// little endian

		if (size_compressed > DBMS_MAX_COMPRESSED_SIZE)
			throw DB::Exception("Too large size_compressed. Most likely corrupted data.", DB::ErrorCodes::TOO_LARGE_SIZE_COMPRESSED);

		size_t size_decompressed = 0;
		memcpy(&size_compressed, &header[5], 4);	/// little endian

		DB::writeText(size_decompressed, out);
		DB::writeChar('\t', out);
		DB::writeText(size_compressed, out);
		DB::writeChar('\n', out);

		in.ignore(size_compressed - COMPRESSED_BLOCK_HEADER_SIZE);
	}
}
Esempio n. 2
0
	void readIntText(T & x, DB::ReadBuffer & buf)
	{
		bool negative = false;
		x = 0;

		if (unlikely(buf.eof()))
			DB::throwReadAfterEOF();

		if (std::is_signed<T>::value && *buf.position() == '-')
		{
			++buf.position();
			negative = true;
		}
		
		if (*buf.position() == '0')
		{
			++buf.position();
			return;
		}

		while (!buf.eof())
		{
			if ((*buf.position() & 0xF0) == 0x30)
			{
				x *= 10;
				x += *buf.position() & 0x0F;
				++buf.position();
			}
			else
				break;
		}

		if (std::is_signed<T>::value && negative)
			x = -x;
	}
Esempio n. 3
0
/// Read and check header of compressed block. Print size of decompressed and compressed data.
std::pair<UInt32, UInt32> stat(DB::ReadBuffer & in, DB::WriteBuffer & out)
{
    if (in.eof())
        return {};

    in.ignore(16);    /// checksum

    char header[COMPRESSED_BLOCK_HEADER_SIZE];
    in.readStrict(header, COMPRESSED_BLOCK_HEADER_SIZE);

    UInt32 size_compressed = unalignedLoad<UInt32>(&header[1]);

    if (size_compressed > DBMS_MAX_COMPRESSED_SIZE)
        throw DB::Exception("Too large size_compressed. Most likely corrupted data.", DB::ErrorCodes::TOO_LARGE_SIZE_COMPRESSED);

    UInt32 size_decompressed = unalignedLoad<UInt32>(&header[5]);

    return {size_compressed, size_decompressed};
}
Esempio n. 4
0
/// Outputs sizes of uncompressed and compressed blocks for compressed file.
void stat(DB::ReadBuffer & in, DB::WriteBuffer & out)
{
    while (!in.eof())
    {
        in.ignore(16);    /// checksum

        char header[COMPRESSED_BLOCK_HEADER_SIZE];
        in.readStrict(header, COMPRESSED_BLOCK_HEADER_SIZE);

        UInt32 size_compressed = unalignedLoad<UInt32>(&header[1]);

        if (size_compressed > DBMS_MAX_COMPRESSED_SIZE)
            throw DB::Exception("Too large size_compressed. Most likely corrupted data.", DB::ErrorCodes::TOO_LARGE_SIZE_COMPRESSED);

        UInt32 size_decompressed = unalignedLoad<UInt32>(&header[5]);

        DB::writeText(size_decompressed, out);
        DB::writeChar('\t', out);
        DB::writeText(size_compressed, out);
        DB::writeChar('\n', out);

        in.ignore(size_compressed - COMPRESSED_BLOCK_HEADER_SIZE);
    }
}