Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(7)  |  Call(7)  |  Derive(0)  |  Import(0)
Reads file in chunks for performance in handling of big files.

:param file: File to be read, e.g. returned by :func:`open`.
:type file: file object

:param chunk_size: Read in this sized chunks, ``None`` defaults to 
    :const:`DEFAULT_CHUNK_SIZE`.
:type chunk_size: int

:param start_position: Start position of the chunked reading, ``-1`` means(more...)

        def chunked_reader(file, chunk_size=None, start_position= -1,
                    max_chunks= -1, reset_offset=True):
    """Reads file in chunks for performance in handling of big files.
    
    :param file: File to be read, e.g. returned by :func:`open`.
    :type file: file object
    
    :param chunk_size: Read in this sized chunks, ``None`` defaults to 
        :const:`DEFAULT_CHUNK_SIZE`.
    :type chunk_size: int
    
    :param start_position: Start position of the chunked reading, ``-1`` means
        that the file is not being seeked to new position.
    :type start_position: int
    
    :param max_chunks: Maximum amount of chunks, ``-1`` means *infinity*.
    :type max_chunks: int
    
    :param reset_offset: Resets the offset of seeking between chunks. Used
        to correct the cursor position when file seeks / reads occurs inside 
        chunk iteration.
    :type reset_offset: bool
    
    :return: Generator of file chunks as tuples of chunk offset and chunk.
    :rtype: generator of (chunk_offset, chunk)
    
    """
    if start_position != -1:
        file.seek(start_position)

    offset = file.tell()
    chunk = ""
    chunk_size = chunk_size or DEFAULT_CHUNK_SIZE

    i = 0
    while True:
        if 0 < max_chunks <= i:
            break

        if reset_offset:
            file.seek(offset + len(chunk))

        offset = file.tell()
        chunk = file.read(chunk_size)
        if not chunk:
            break
        yield (offset, chunk)
        i += 1
        


src/m/p/mpeg1audio-0.5.2/src/mpeg1audio/__init__.py   mpeg1audio(Download)
        # TODO: LOW: Free bitrate.
        next_frame_offset = self.offset + self.size
        chunks = utils.chunked_reader(file, start_position=next_frame_offset,
                                       chunk_size=chunk_size)
        return MPEGAudioFrame.parse_consecutive(next_frame_offset, chunks)
 
        chunk_size = max(chunk_size, 4)
        chunks = utils.chunked_reader(file, chunk_size=chunk_size,
                                start_position=begin_frame_search,
                                max_chunks=max_chunks)
 
        for chunk_offset, chunk in chunks:
            for found in utils.find_all_overlapping(chunk, chr(255)):
                consecutive_chunks = \
                    utils.chunked_reader(file,

src/m/p/mpeg1audio-HEAD/src/mpeg1audio/__init__.py   mpeg1audio(Download)
        # TODO: LOW: Free bitrate.
        next_frame_offset = self.offset + self.size
        chunks = utils.chunked_reader(file, start_position=next_frame_offset,
                                       chunk_size=chunk_size)
        return MPEGAudioFrame.parse_consecutive(next_frame_offset, chunks)
 
        chunk_size = max(chunk_size, 4)
        chunks = utils.chunked_reader(file, chunk_size=chunk_size,
                                start_position=begin_frame_search,
                                max_chunks=max_chunks)
 
        for chunk_offset, chunk in chunks:
            for found in utils.find_all_overlapping(chunk, chr(255)):
                consecutive_chunks = \
                    utils.chunked_reader(file,

src/m/p/mpeg1audio-HEAD/tests/tests.py   mpeg1audio(Download)
    def testParseConsecutive(self):
        """Chunked parse consecutive"""
        chunks = utils.chunked_reader(self.file, chunk_size=4)
        self.assertEqual([2283, 3119, 3955], [f.offset for f in utils.genlimit(MPEGAudioFrame.parse_consecutive(header_offset=2283, chunks=chunks), 2, 3)])