python附加模式_如何使用Python在附加模式下在GCS存储桶中打开文件?

bd96500e110b49cbb3cd949968f18be7.png

I've looked at all related questions and all I can find are uploading to GCS and not writing. I'm not trying to upload a file or create a new one. I need to open the file located in a google cloud storage bucket in append mode i.e create it if it doesn't exist and write to the end of it using python. If anybody could point me in the right direction, I'd be really grateful.

The upload method replaces my file each time. I've tried downloading, appending and then replacing but this requires the file to be initially present in the directory.

Is there a way to implement the append mode functionality in gcs?

PS: I'm trying to do this in cloud functions and not a machine equipped with the Cloud SDK

解决方案

There's no way to do this, because objects in GCS are immutable.

Objects are immutable, which means that an uploaded object cannot change throughout its storage lifetime. An object's storage lifetime is the time between successful object creation (upload) and successful object deletion. In practice, this means that you cannot make incremental changes to objects, such as append operations or truncate operations. However, it is possible to overwrite objects that are stored in Cloud Storage, and doing so happens atomically — until the new upload completes the old version of the object will be served to readers, and after the upload completes the new version of the object will be served to readers. So a single overwrite operation simply marks the end of one immutable object's lifetime and the beginning of a new immutable object's lifetime.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值