Respect buffering, encoding, newline, closefd, and opener if we're looking at a local file
This commit is contained in:
parent
ad08830421
commit
90e2e1f7d2
@ -36,11 +36,13 @@ def copy_remote(src, dst, overwrite=False):
|
||||
return gfile.copy(src, dst, overwrite)
|
||||
|
||||
|
||||
def open_remote(path, mode):
|
||||
def open_remote(path, mode='r', buffering=-1, encoding=None, newline=None, closefd=True, opener=None):
|
||||
"""
|
||||
Wrapper around open_remote() method that can handle remote paths like `gs://...`
|
||||
off Google Cloud using Tensorflow's IO helpers.
|
||||
|
||||
buffering, encoding, newline, closefd, and opener are ignored for remote files
|
||||
|
||||
This enables us to do:
|
||||
with open_remote('gs://.....', mode='w+') as f:
|
||||
do something with the file f, whether or not we have local access to it
|
||||
@ -49,7 +51,7 @@ def open_remote(path, mode):
|
||||
if is_remote_path(path):
|
||||
from tensorflow.io import gfile
|
||||
return gfile.GFile(path, mode=mode)
|
||||
return open_remote(path, mode)
|
||||
return open(path, mode, buffering=buffering, encoding=encoding, newline=newline, closefd=closefd, opener=opener)
|
||||
|
||||
|
||||
def isdir_remote(path):
|
||||
|
Loading…
x
Reference in New Issue
Block a user