Skip to content

Commit ebb8a6b

Browse files
author
yhori991
committed
Changed the s3file.load API design
Previous s3file.laod returns BytesIO or StringIO but now it returns raw content of the file (instance of either `str` or `bytes`.
1 parent efd51cc commit ebb8a6b

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

s3file/__S3File.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import os
23
import boto3
34
from io import BytesIO, StringIO
@@ -8,9 +9,14 @@
89
__DEFAULT_TEMP_DIR = '/tmp/s3file'
910

1011

12+
thismodule = sys.modules[__name__]
1113
s3 = boto3.resource('s3')
1214

1315

16+
def s3_set_profile(profile_name):
17+
thismodule.s3 = boto3.session.Session(profile_name=profile_name).resource('s3')
18+
19+
1420
def _split_into_bucket_and_key(path):
1521
bucket, key = '', ''
1622
path_split = path.split('/')
@@ -136,13 +142,7 @@ def s3_load(path, mode='rb', force_download=False, cache_dir=__DEFAULT_CACHE_DIR
136142
with open(local, mode) as fp:
137143
content = fp.read()
138144

139-
# return StringIO or BytesIO
140-
if mode == 'r':
141-
return StringIO(content)
142-
elif mode == 'rb':
143-
return BytesIO(content)
144-
else:
145-
return None
145+
return content
146146

147147

148148
def s3_save(path, content, cache_dir=__DEFAULT_CACHE_DIR):

s3file/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# from .__S3File import s3_set_profile as set_profile
12
from .__S3File import s3_xlist as xlist
23
from .__S3File import s3_download as download
34
from .__S3File import s3_upload as upload

s3file/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__title__ = 'py-s3file'
33
__description__ = 'A simple utility tool to access s3 object through basic File I/O operations.'
44
__copywrite__ = 'Copyright (C) yhori991'
5-
__version__ = '0.0.3'
5+
__version__ = '0.0.4'
66
__license__ = 'MIT'
77
__author__ = 'yhori991'
88
__author_email__ = '[email protected]'

tests/test_s3file_txt.py

Whitespace-only changes.

0 commit comments

Comments
 (0)