mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 17:41:59 +00:00
Fixed LimitReadBuffer [#CLICKHOUSE-2].
This commit is contained in:
parent
f8513b932f
commit
4272265128
@ -22,7 +22,14 @@ bool LimitReadBuffer::nextImpl()
|
||||
|
||||
|
||||
LimitReadBuffer::LimitReadBuffer(ReadBuffer & in_, size_t limit_)
|
||||
: ReadBuffer(nullptr, 0), in(in_), limit(limit_) {}
|
||||
: ReadBuffer(in_.position(), 0), in(in_), limit(limit_)
|
||||
{
|
||||
size_t remaining_bytes_in_buffer = in.buffer().end() - in.position();
|
||||
if (remaining_bytes_in_buffer > limit)
|
||||
remaining_bytes_in_buffer = limit;
|
||||
|
||||
working_buffer = Buffer(in.position(), in.position() + remaining_bytes_in_buffer);
|
||||
}
|
||||
|
||||
|
||||
LimitReadBuffer::~LimitReadBuffer()
|
||||
|
@ -14,11 +14,20 @@ int main(int argc, char ** argv)
|
||||
size_t limit = std::stol(argv[1]);
|
||||
|
||||
ReadBufferFromFileDescriptor in(STDIN_FILENO);
|
||||
LimitReadBuffer limit_in(in, limit);
|
||||
|
||||
WriteBufferFromFileDescriptor out(STDOUT_FILENO);
|
||||
|
||||
copyData(limit_in, out);
|
||||
writeCString("--- first ---\n", out);
|
||||
{
|
||||
LimitReadBuffer limit_in(in, limit);
|
||||
copyData(limit_in, out);
|
||||
}
|
||||
|
||||
writeCString("\n--- second ---\n", out);
|
||||
{
|
||||
LimitReadBuffer limit_in(in, limit);
|
||||
copyData(limit_in, out);
|
||||
}
|
||||
|
||||
writeCString("\n--- the rest ---\n", out);
|
||||
copyData(in, out);
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
--- first ---
|
||||
Hello, wor
|
||||
--- second ---
|
||||
ld! Abcdef
|
||||
--- the rest ---
|
||||
ld!
|
||||
ghijklmnopqrstuvwxyz.
|
||||
|
@ -1,2 +1,2 @@
|
||||
#!/usr/bin/env bash
|
||||
./limit_read_buffer 10 <<< "Hello, world!"
|
||||
./limit_read_buffer 10 <<< 'Hello, world! Abcdefghijklmnopqrstuvwxyz.'
|
||||
|
Loading…
Reference in New Issue
Block a user