读取块文件

read_in_chunks

def read_in_chunks(filePath, chunk_size=1024*1024):
    """
    Lazy function (generator) to read a file piece by piece.
    Default chunk size: 1M
    You can set your own chunk size
    """
    file_object = open(filePath,'rb')
    while True:
        chunk_data = file_object.read(chunk_size) # .read(size) 读取size个字节
        if not chunk_data:
            break
        yield chunk_data
if __name__ == "__main__":
    filePath = '20211008.mp3'
    i = 0 
    for chunk in read_in_chunks(filePath):
        print("len",len(chunk))
        print(i)

Progress of Python requests post - Stack Overflow
python requests upload large file with additional data - Stack Overflow

上一篇:重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件增加了 PlaceholderText 属性


下一篇:6.824 笔记