def read()

in azure/datalake/store/core.py [0:0]


    def read(self, length=-1):
        """
        Return data from cache, or fetch pieces as necessary

        Parameters
        ----------
        length: int (-1)
            Number of bytes to read; if <0, all remaining bytes.
        """
        if self.mode != 'rb':
            raise ValueError('File not in read mode')
        if length < 0:
            length = self.size
        if self.closed:
            raise ValueError('I/O operation on closed file.')
        flag = 0
        out = b""
        while length > 0:
            self._read_blocksize()
            data_read = self.cache[self.loc - self.start:
                                   min(self.loc - self.start + length, self.end - self.start)]
            if not data_read:  # Check to catch possible server errors. Ideally shouldn't happen.
                flag += 1
                if flag >= 5:
                    exception_string = "Current Location:{loc}, " \
                                       "File Size:{size}, Cache Start:{start}, " \
                                       "Cache End:{end}".format(loc=self.loc, size=self.size,
                                                                start=self.start, end=self.end)
                    raise DatalakeIncompleteTransferException('Could not read data: {path}. '
                                                              'Repeated zero byte reads. Possible file corruption. File Details'
                                                              '{details}'.format(path=self.path, details=exception_string))
            out += data_read
            self.loc += len(data_read)
            length -= len(data_read)
            if self.loc >= self.size:
                length = 0

        return out