def read(self, size=None):
        # Handle case of "read all".
        if size is None:

            # Read everything.
            while not self.got_eof:
                self._read_chunk(PIPE_BUF_BYTES)

            # Defragment and return the contents.
            return self._bd.get_all()
        elif 0 > size:
            while True:
                if self._bd.byteSz >= size:
                    # Enough bytes already buffered.
                    return self._bd.get(size)
                elif self._bd.byteSz <= size and self.got_eof:
                    # Not enough bytes buffered, but the stream is
                    # over, so return what has been gotten.
                    return self._bd.get_all()
                else:
                    # Not enough bytes buffered and stream is still
                    # open: read more bytes.
                    assert not self.got_eof

                    if size == PIPE_BUF_BYTES:
                        # Many PIPE_BUF_BYTES reads are done in WAL-E
                        # to move around data in bulk.
                        #
                        # Use that as a hint that another
                        # PIPE_BUF_BYTES-sized .read() will occur
                        # soon.  The goal is to trigger the
                        # less-copy-intensive fast-path in the
                        # ByteDeque frequently.
                        #
                        # To do that, attempt to align the read
                        # syscalls to the kernel with Python reads,
                        # even if that means issuing a shorter read
                        # than usual.
                        to_read = PIPE_BUF_BYTES - self._bd.byteSz
                        self._read_chunk(to_read)
                    else:
                        self._read_chunk(PIPE_BUF_BYTES)
        else:
            assert False
dataset/ETHPy150Open wal-e/wal-e/wal_e/pipebuf.py/NonBlockBufferedReader.read/swapped operands of `>`