def _recv_to_fd()

in nailgun-client/py/ng.py [0:0]


    def _recv_to_fd(self, dest_file, num_bytes):
        """
        Receives num_bytes bytes from the nailgun socket and copies them to the specified file
        object. Used to route data to stdout or stderr on the client.
        """
        bytes_read = 0
        dest_fd = dest_file
        flush = False
        if dest_file and hasattr(dest_file, 'buffer'):
            dest_fd = dest_file.buffer
            flush = True
            # Make sure we've written anything that already existed in the buffer
            dest_fd.flush()

        while bytes_read < num_bytes:
            bytes_to_read = min(len(self.buf), num_bytes - bytes_read)
            bytes_received = self.transport.recv_into(self.buf, bytes_to_read)
            if dest_fd:
                dest_fd.write(self.buf[:bytes_received])
                if flush:
                    dest_fd.flush()
            bytes_read += bytes_received