@@ -394,10 +394,14 @@ def __setitem__(self, key, value):
394
394
self .write (field , record )
395
395
else :
396
396
# metadata or top-level
397
- self ._items [key ] = value
398
- new_value = json .loads (
399
- value .decode () if isinstance (value , bytes ) else value
400
- )
397
+ if hasattr (value , "to_bytes" ):
398
+ val = value .to_bytes ().decode ()
399
+ elif isinstance (value , bytes ):
400
+ val = value .decode ()
401
+ else :
402
+ val = value
403
+ self ._items [key ] = val
404
+ new_value = json .loads (val )
401
405
self .zmetadata [key ] = {** self .zmetadata .get (key , {}), ** new_value }
402
406
403
407
@staticmethod
@@ -606,6 +610,7 @@ class ReferenceFileSystem(AsyncFileSystem):
606
610
"""
607
611
608
612
protocol = "reference"
613
+ cachable = False
609
614
610
615
def __init__ (
611
616
self ,
@@ -762,6 +767,11 @@ def __init__(
762
767
for k , f in self .fss .items ():
763
768
if not f .async_impl :
764
769
self .fss [k ] = AsyncFileSystemWrapper (f )
770
+ elif self .asynchronous ^ f .asynchronous :
771
+ raise ValueError (
772
+ "Reference-FS's target filesystem must have same value"
773
+ "of asynchronous"
774
+ )
765
775
766
776
def _cat_common (self , path , start = None , end = None ):
767
777
path = self ._strip_protocol (path )
@@ -772,6 +782,8 @@ def _cat_common(self, path, start=None, end=None):
772
782
raise FileNotFoundError (path ) from exc
773
783
if isinstance (part , str ):
774
784
part = part .encode ()
785
+ if hasattr (part , "to_bytes" ):
786
+ part = part .to_bytes ()
775
787
if isinstance (part , bytes ):
776
788
logger .debug (f"Reference: { path } , type bytes" )
777
789
if part .startswith (b"base64:" ):
@@ -1073,7 +1085,7 @@ def _dircache_from_items(self):
1073
1085
self .dircache = {"" : []}
1074
1086
it = self .references .items ()
1075
1087
for path , part in it :
1076
- if isinstance (part , (bytes , str )):
1088
+ if isinstance (part , (bytes , str )) or hasattr ( part , "to_bytes" ) :
1077
1089
size = len (part )
1078
1090
elif len (part ) == 1 :
1079
1091
size = None
@@ -1104,6 +1116,7 @@ def _open(self, path, mode="rb", block_size=None, cache_options=None, **kwargs):
1104
1116
return io .BytesIO (data )
1105
1117
1106
1118
def ls (self , path , detail = True , ** kwargs ):
1119
+ logger .debug ("list %s" , path )
1107
1120
path = self ._strip_protocol (path )
1108
1121
if isinstance (self .references , LazyReferenceMapper ):
1109
1122
try :
0 commit comments