将文件写入多个块。
项目描述
ChunkedFile
一个文件句柄,将子序列写入分组在一起,并定期将它们作为单独的文件写入。对于不支持文件追加的文件系统(如GCS FUSE)非常有用。可以将Pathlib修补以用分块文件替换以追加模式打开的文件,因此外部库无需更改。
用法
使用ChunkedFile
import time
import chunkedfile
# Write chunks up to every 10 minutes.
with chunkedfile.ChunkedFile('filename.txt', 600) as f:
# The first chunk will be written on the first write after the sleep.
f.write('Lorem\n')
time.sleep(1000)
f.write('Ipsum\n')
# The last chunk is automatically written when the file is closed.
f.write('Dolor\n')
f.write('Sit\n')
# The directory now contains two files:
# - filename.txt-1-20210904T130400
# - filename.txt-2-20210904T132100
使用pathlib.Path
import time
import pathlib
import chunkedfile
# Path objects opened in append mode will be replaced by chunked files.
chunkedfile.patch_pathlib_append(600)
# Write chunks up to every 10 minutes.
with pathlib.Path('filename.txt').open('a') as f:
# The first chunk will be written during the sleep command.
f.write('Lorem\n')
f.write('Ipsum\n')
time.sleep(1000)
# The last chunk is automatically written when the file is closed.
f.write('Dolor\n')
f.write('Sit\n')
# The directory now contains two files:
# - filename.txt-1-20210904T130400
# - filename.txt-2-20210904T132100
项目细节
关闭
chunkedfile-0.3.0.tar.gz的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 170c67b311bcfc477b2344f664902c585193bc30bd99e41ef04b40e48c0f844a |
|
MD5 | 25754efbcdfae72e53a66942b1dea5fb |
|
BLAKE2b-256 | 319d1ee08c0a371f43beb319d98d4ce8a00e9d70f38f77383d5b404803edb4ca |