@@ -610,18 +610,36 @@ def download(self, filename=None):
610610 with open (filename , 'wb' ) as outfile :
611611 outfile .write (infile .read ())
612612
613- def remote_open (self ):
613+ def remote_open (self , mode = 'b' , encoding = 'ascii' , errors = 'ignore' ):
614614 """Open the remote dataset for random access.
615615
616616 Get a file-like object for reading from the remote dataset, providing random access,
617617 similar to a local file.
618618
619+ Parameters
620+ ----------
621+ mode : 'b' or 't', optional
622+ Mode with which to open the remote data; 'b' for binary, 't' for text. Defaults
623+ to 'b'.
624+
625+ encoding : str, optional
626+ If ``mode`` is text, the encoding to use to decode the binary data into text.
627+ Defaults to 'ascii'.
628+
629+ errors : str, optional
630+ If ``mode`` is text, the error handling behavior to pass to `bytes.decode`.
631+ Defaults to 'ignore'.
632+
619633 Returns
620634 -------
621635 A random access, file-like object
622636
623637 """
624- return self .access_with_service ('HTTPServer' )
638+ fobj = self .access_with_service ('HTTPServer' )
639+ if mode == 't' :
640+ from io import StringIO
641+ fobj = StringIO (fobj .read ().decode (encoding , errors ))
642+ return fobj
625643
626644 def remote_access (self , service = None , use_xarray = None ):
627645 """Access the remote dataset.
@@ -714,7 +732,7 @@ def access_with_service(self, service, use_xarray=None):
714732 import xarray as xr
715733 provider = xr .open_dataset
716734 except ImportError :
717- raise ImportError ('xarray to be installed if `use_xarray` is True.' )
735+ raise ImportError ('xarray needs to be installed if `use_xarray` is True.' )
718736 else :
719737 try :
720738 from netCDF4 import Dataset as NC4Dataset
0 commit comments