Demo entry 6355390

py

   

Submitted by anonymous on Apr 13, 2017 at 18:09
Language: Python. Code size: 615 Bytes.

def read(path, read_items, write_items):
    '''
    @path 文件路径
    @read_items 待读取文件块队列
    @write_items 待写入文件块队列
    每次从待读取文件块队列获取文件块偏移,
    从文件中读取对应内容,并加入待写入文件块队列
    '''
    try:
        file = open(path, mode='rb')

        buf = None
        while not read_items.empty():
            offset = read_items.get()
            file.seek(offset)
            buf = file.read(FILE_READ_SIZE)
            write_items.put({
                'offset': offset,
                'buf': buf,
            })
            read_items.task_done()

        file.close()
    except Exception, e:
        pass

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).