跳转到主要内容

将文件写入多个块。

项目描述

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 (2.1 kB 查看散列)

上传时间

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面