@@ -49,6 +49,7 @@ def __init__(
49
49
self .bucket = bucket
50
50
self .key = key
51
51
self .position = 0
52
+ self ._size = file .size
52
53
self .file = file
53
54
self .raw = None
54
55
self .line_terminator = line_terminator
@@ -66,7 +67,7 @@ def close(self) -> None:
66
67
67
68
@property
68
69
def size (self ) -> int :
69
- return self .file . size
70
+ return self ._size
70
71
71
72
@property
72
73
def closed (self ) -> bool :
@@ -102,7 +103,7 @@ def seek(self, offset: int, whence: int = io.SEEK_SET) -> int:
102
103
elif whence == io .SEEK_CUR :
103
104
self .position += offset
104
105
elif whence == io .SEEK_END :
105
- self .position = self .file . size + offset
106
+ self .position = self .size + offset
106
107
return self .position
107
108
108
109
def tell (self ) -> int :
@@ -119,24 +120,22 @@ def read(self, limit: int = -1):
119
120
"""
120
121
self .checkClosed ()
121
122
self .checkReadable ()
122
- maxcount = self .file . size - self .position
123
+ maxcount = self .size - self .position
123
124
assert maxcount >= 0
124
125
count = limit
125
126
if limit == 0 :
126
127
return b""
127
128
if limit < 0 or limit > maxcount :
128
129
count = maxcount
129
- buffer = bytearray (count )
130
- count = self .readinto (buffer )
131
- if count < len (buffer ):
132
- return buffer [0 :count ]
133
- return buffer
130
+
131
+ count = maxcount - self .position
132
+ return self .file .read1 (self .position , count )
134
133
135
134
def readinto (self , buffer ):
136
135
self .checkReadable ()
137
136
if self .closed :
138
137
return - 1
139
- count = self .file .read (buffer , self .position , len (buffer ))
138
+ count = self .file .readinto1 (buffer , self .position , len (buffer ))
140
139
self .position += count
141
140
return count
142
141
@@ -148,13 +147,13 @@ def readline(self, limit: int = -1) -> bytes:
148
147
print ("readline " + limit )
149
148
if limit != - 1 :
150
149
raise NotImplementedError ("limits other than -1 not implemented yet" )
151
- buffer = bytearray (self .buffer_size )
150
+ # buffer = bytearray(self.buffer_size)
152
151
line = io .BytesIO ()
153
152
154
153
while True :
155
154
previous_position = self .position
156
- count = self .readinto ( buffer )
157
- if count == 0 :
155
+ buffer = self .file . read ( self . position , self . buffer_size )
156
+ if len ( buffer ) == 0 :
158
157
break
159
158
index = buffer .find (self .line_terminator , 0 )
160
159
if index > 0 :
@@ -167,7 +166,7 @@ def readline(self, limit: int = -1) -> bytes:
167
166
def readall (self ) -> bytes :
168
167
self .checkClosed ()
169
168
170
- length = self .file . size - self .position
169
+ length = self .size - self .position
171
170
buffer = bytearray (length )
172
171
count = self .readinto (buffer )
173
172
return buffer [0 :count ]
@@ -290,6 +289,8 @@ def register_object_store(
290
289
):
291
290
GEDSInstance .register_object_store (bucket , endpoint_url , access_key , secret_key )
292
291
292
+ def relocate (force : bool = False ):
293
+ GEDSInstance .get ().relocate (force )
293
294
294
295
def parse_uri (uri : str ):
295
296
path = uri .removeprefix ("geds://" )
@@ -328,10 +329,12 @@ def open(bucket: str, key: str, mode: str, client=None):
328
329
if mode == constants .READ_BINARY :
329
330
f = client .open (bucket , key )
330
331
elif mode == constants .WRITE_BINARY :
331
- try :
332
+ f = client .create (bucket , key , True )
333
+ elif mode == 'ab' :
334
+ f = client .open (bucket , key )
335
+ if not f .writable ():
336
+ client .copy (bucket , key , bucket , key )
332
337
f = client .open (bucket , key )
333
- except :
334
- f = client .create (bucket , key )
335
338
else :
336
339
raise ValueError (f"Invalid argument for mode: { mode } " )
337
340
return GEDSRawInputBase (
0 commit comments