level 5
将就将就ლ
楼主
### 分块读取超大文件
.
CHUNK_SIZE = 1024
chunk_data = None
.
async with aiofiles.open(bigfile_path, mode=mode) as bigf:
while True:
chunk_data = await bigf.read(CHUNK_SIZE)
if not chunk_data:
break
.
use_data(chunk_data)
.
.
.
.
总结核心调用:
1. while True:死循环
2. await bigf.read函数传入“本次读取操作读取的字节数上限”
3. if not chunk_data: break当读取到的字节数量为0时,表示读取到EOF,即整个文件都已被读完了,可结束循环
2025年12月07日 16点12分
1
.
CHUNK_SIZE = 1024
chunk_data = None
.
async with aiofiles.open(bigfile_path, mode=mode) as bigf:
while True:
chunk_data = await bigf.read(CHUNK_SIZE)
if not chunk_data:
break
.
use_data(chunk_data)
.
.
.
.
总结核心调用:
1. while True:死循环
2. await bigf.read函数传入“本次读取操作读取的字节数上限”
3. if not chunk_data: break当读取到的字节数量为0时,表示读取到EOF,即整个文件都已被读完了,可结束循环