def read(self, length=-1):

        blockPos = self.position & self._container.BLOCK_MASK
        offset = 0

        if length < 0:
            length = self.length - self.position

        if self.position + length > self.length:
            length = self.length - self.position

        if not length:
            return ''

        buffer = allocateBuffer(int(length))

        while blockPos + length >= self._container.BLOCK_LEN:
            blockLen = self._container.BLOCK_LEN - blockPos

            data = self._block.read(blockLen)
            buffer[offset:offset + blockLen] = data

            length -= blockLen
            offset += blockLen
            self.position += blockLen

            self._block.seek(self.position)
            blockPos = 0

        if length > 0:
            buffer[offset:offset + length] = self._block.read(length)
            self.position += length
            offset += length

        return buffer[0:offset]
Ejemplo n.º 2
0
    def read(self, length=-1):

        blockPos = self.position & self._container.BLOCK_MASK
        offset = 0

        if length < 0:
            length = self.length - self.position

        if self.position + length > self.length:
            length = self.length - self.position

        if not length:
            return ''

        buffer = allocateBuffer(int(length))

        while blockPos + length >= self._container.BLOCK_LEN:
            blockLen = self._container.BLOCK_LEN - blockPos

            data = self._block.read(blockLen)
            buffer[offset:offset+blockLen] = data

            length -= blockLen
            offset += blockLen
            self.position += blockLen

            self._block.seek(self.position)
            blockPos = 0

        if length > 0:
            buffer[offset:offset+length] = self._block.read(length)
            self.position += length
            offset += length

        return buffer[0:offset]
    def seek(self, position, write=False):

        position = int(position)
        key = pack('>16sii', self._key[0:16], 0,
                   position >> self._container.BLOCK_SHIFT)

        if self._data is None or key != self._key:
            self._key = key
            container = self._container
            data = container.get(self._key, container._blocks)

            if data is not None:
                self._len = len(data)
                if write:
                    self._data = allocateBuffer(self._container.BLOCK_LEN)
                    self._data[0:self._len] = data
                else:
                    self._data = buffer(data)
            else:
                self._data = allocateBuffer(self._container.BLOCK_LEN)

        self._position = position & self._container.BLOCK_MASK
Ejemplo n.º 4
0
    def seek(self, position, write=False):

        position = int(position)
        key = pack('>16sii', self._key[0:16], 0,
                   position >> self._container.BLOCK_SHIFT)

        if self._data is None or key != self._key:
            self._key = key
            container = self._container
            data = container.get(self._key, container._blocks)

            if data is not None:
                self._len = len(data)
                if write:
                    self._data = allocateBuffer(self._container.BLOCK_LEN)
                    self._data[0:self._len] = data
                else:
                    self._data = buffer(data)
            else:
                self._data = allocateBuffer(self._container.BLOCK_LEN)

        self._position = position & self._container.BLOCK_MASK