You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: open_reader accepts optional size to skip HEAD request (#664)
* feat: open_reader accepts optional size to skip HEAD request
* feat(fsspec): BufferedFile forwards size to open_reader
* refactor(buffered): drop ObjectMeta from ReadableFile
Copy file name to clipboardExpand all lines: obstore/python/obstore/_buffered.pyi
+5-38Lines changed: 5 additions & 38 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,6 @@ from contextlib import AbstractAsyncContextManager, AbstractContextManager
3
3
4
4
from ._attributesimportAttributes
5
5
from ._bytesimportBytes
6
-
from ._listimportObjectMeta
7
6
from ._storeimportObjectStore
8
7
9
8
ifsys.version_info>= (3, 11):
@@ -16,16 +15,12 @@ if sys.version_info >= (3, 12):
16
15
else:
17
16
fromtyping_extensionsimportBuffer
18
17
19
-
ifsys.version_info>= (3, 13):
20
-
fromwarningsimportdeprecated
21
-
else:
22
-
fromtyping_extensionsimportdeprecated
23
-
24
18
defopen_reader(
25
19
store: ObjectStore,
26
20
path: str,
27
21
*,
28
22
buffer_size: int=1024*1024,
23
+
size: int|None=None,
29
24
) ->ReadableFile:
30
25
"""Open a readable file object from the specified location.
31
26
@@ -35,6 +30,9 @@ def open_reader(
35
30
36
31
Keyword Args:
37
32
buffer_size: The minimum number of bytes to read in a single request. Up to `buffer_size` bytes will be buffered in memory.
33
+
size: Optional byte size of the object. When provided, skips the HEAD request used to fetch the file size. Useful for callers that already know the size from external metadata.
34
+
35
+
The caller is responsible for accuracy: a value larger than the actual file surfaces as a read-time range error, a value smaller causes silent truncation. Defaults to `None`.
38
36
39
37
Returns:
40
38
ReadableFile
@@ -46,6 +44,7 @@ async def open_reader_async(
46
44
path: str,
47
45
*,
48
46
buffer_size: int=1024*1024,
47
+
size: int|None=None,
49
48
) ->AsyncReadableFile:
50
49
"""Call `open_reader` asynchronously, returning a readable file object with asynchronous operations.
51
50
@@ -92,22 +91,6 @@ class ReadableFile:
92
91
This is currently a no-op.
93
92
"""
94
93
95
-
@property
96
-
@deprecated(
97
-
"`ReadableFile.meta` is deprecated and will be removed in a future release. "
98
-
"Use the `head` or `head_async` methods directly if you need object metadata.",
99
-
)
100
-
defmeta(self) ->ObjectMeta:
101
-
"""Access the metadata of the underlying file.
102
-
103
-
!!! warning "Deprecated"
104
-
105
-
This attribute is deprecated and will be removed in a future
106
-
release. Use the [`head`][obstore.head] or
107
-
[`head_async`][obstore.head_async] methods directly if you need
108
-
object metadata.
109
-
"""
110
-
111
94
defread(self, size: int|None=None, /) ->Bytes:
112
95
"""Read up to `size` bytes from the object and return them.
113
96
@@ -186,22 +169,6 @@ class AsyncReadableFile:
186
169
This is currently a no-op.
187
170
"""
188
171
189
-
@property
190
-
@deprecated(
191
-
"`AsyncReadableFile.meta` is deprecated and will be removed in a future release. "
192
-
"Use the `head` or `head_async` methods directly if you need object metadata.",
193
-
)
194
-
defmeta(self) ->ObjectMeta:
195
-
"""Access the metadata of the underlying file.
196
-
197
-
!!! warning "Deprecated"
198
-
199
-
This attribute is deprecated and will be removed in a future
200
-
release. Use the [`head`][obstore.head] or
201
-
[`head_async`][obstore.head_async] methods directly if you need
0 commit comments