From efe11ee58a9a7ed7a3d890fff257b7d416782a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Kry=C5=84ski?= Date: Sun, 17 Nov 2019 15:48:22 +0100 Subject: [PATCH] readd support for append --- fs_s3fs/_s3fs.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fs_s3fs/_s3fs.py b/fs_s3fs/_s3fs.py index ac2a6f1..fb33f4d 100644 --- a/fs_s3fs/_s3fs.py +++ b/fs_s3fs/_s3fs.py @@ -25,6 +25,7 @@ from fs.subfs import SubFS from fs.path import basename, dirname, forcedir, join, normpath, relpath from fs.time import datetime_to_epoch +from fs.tools import copy_file_data from ._s3fs_file import S3InputFile, S3OutputFile @@ -417,9 +418,6 @@ def openbin(self, path, mode="r", buffering=-1, **options): _path = self.validatepath(path) _key = self._path_to_key(_path) - if _mode.appending: - raise errors.ResourceError(path, msg="append mode is not supported") - if _mode.create: if self.strict: try: @@ -441,10 +439,22 @@ def openbin(self, path, mode="r", buffering=-1, **options): raise errors.FileExpected(path) obj = self.s3.Object(self._bucket_name, _key) - return S3OutputFile( + s3_file = S3OutputFile( obj, upload_kwargs=self._get_upload_args(_key) ) + if _mode.appending: + with s3errors(path): + try: + s3_in_file = S3InputFile(obj) + copy_file_data( + s3_in_file, + s3_file, + chunk_size=s3_file._min_part_size, + ) + except errors.ResourceNotFound: + pass + return s3_file if self.strict: info = self.getinfo(path)