Skip to content

Commit

Permalink
readd support for append
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-its committed Nov 17, 2019
1 parent 695b879 commit 2c919fe
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions fs_s3fs/_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
try:
with s3errors(path):
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)
Expand Down

0 comments on commit 2c919fe

Please sign in to comment.