@@ -74,6 +74,158 @@ export interface StatOptions {
7474 */
7575 overrideContentDisposition ?: string
7676}
77+ export interface ReadOptions {
78+ /**
79+ * Set `version` for this operation.
80+ *
81+ * This option can be used to retrieve the data of a specified version of the given path.
82+ */
83+ version ?: string
84+ /**
85+ * Set `concurrent` for the operation.
86+ *
87+ * OpenDAL by default to read file without concurrent. This is not efficient for cases when users
88+ * read large chunks of data. By setting `concurrent`, opendal will reading files concurrently
89+ * on support storage services.
90+ *
91+ * By setting `concurrent`, opendal will fetch chunks concurrently with
92+ * the give chunk size.
93+ */
94+ concurrent ?: number
95+ /**
96+ * Sets the chunk size for this operation.
97+ *
98+ * OpenDAL will use services' preferred chunk size by default. Users can set chunk based on their own needs.
99+ */
100+ chunk ?: number
101+ /**
102+ * Controls the optimization strategy for range reads in [`Reader::fetch`].
103+ *
104+ * When performing range reads, if the gap between two requested ranges is smaller than
105+ * the configured `gap` size, OpenDAL will merge these ranges into a single read request
106+ * and discard the unrequested data in between. This helps reduce the number of API calls
107+ * to remote storage services.
108+ *
109+ * This optimization is particularly useful when performing multiple small range reads
110+ * that are close to each other, as it reduces the overhead of multiple network requests
111+ * at the cost of transferring some additional data.
112+ */
113+ gap ?: bigint
114+ /**
115+ * Sets the offset (starting position) for range read operations.
116+ * The read will start from this position in the file.
117+ */
118+ offset ?: bigint
119+ /**
120+ * Sets the size (length) for range read operations.
121+ * The read will continue for this many bytes after the offset.
122+ */
123+ size ?: bigint
124+ /**
125+ * Sets if-match condition for this operation.
126+ * If file exists and its etag doesn't match, an error will be returned.
127+ */
128+ ifMatch ?: string
129+ /**
130+ * Sets if-none-match condition for this operation.
131+ * If file exists and its etag matches, an error will be returned.
132+ */
133+ ifNoneMatch ?: string
134+ /**
135+ * Sets if-modified-since condition for this operation.
136+ * If file exists and hasn't been modified since the specified time, an error will be returned.
137+ * ISO 8601 formatted date string
138+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
139+ */
140+ ifModifiedSince ?: string
141+ /**
142+ * Sets if-unmodified-since condition for this operation.
143+ * If file exists and has been modified since the specified time, an error will be returned.
144+ * ISO 8601 formatted date string
145+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
146+ */
147+ ifUnmodifiedSince ?: string
148+ /**
149+ * Specify the `content-type` header that should be sent back by the operation.
150+ *
151+ * This option is only meaningful when used along with presign.
152+ */
153+ contentType ?: string
154+ /**
155+ * Specify the `cache-control` header that should be sent back by the operation.
156+ *
157+ * This option is only meaningful when used along with presign.
158+ */
159+ cacheControl ?: string
160+ /**
161+ * Specify the `content-disposition` header that should be sent back by the operation.
162+ *
163+ * This option is only meaningful when used along with presign.
164+ */
165+ contentDisposition ?: string
166+ }
167+ export interface ReaderOptions {
168+ /**
169+ * Set `version` for this operation.
170+ *
171+ * This option can be used to retrieve the data of a specified version of the given path.
172+ */
173+ version ?: string
174+ /**
175+ * Set `concurrent` for the operation.
176+ *
177+ * OpenDAL by default to read file without concurrent. This is not efficient for cases when users
178+ * read large chunks of data. By setting `concurrent`, opendal will reading files concurrently
179+ * on support storage services.
180+ *
181+ * By setting `concurrent`, opendal will fetch chunks concurrently with
182+ * the give chunk size.
183+ */
184+ concurrent ?: number
185+ /**
186+ * Sets the chunk size for this operation.
187+ *
188+ * OpenDAL will use services' preferred chunk size by default. Users can set chunk based on their own needs.
189+ */
190+ chunk ?: number
191+ /**
192+ * Controls the optimization strategy for range reads in [`Reader::fetch`].
193+ *
194+ * When performing range reads, if the gap between two requested ranges is smaller than
195+ * the configured `gap` size, OpenDAL will merge these ranges into a single read request
196+ * and discard the unrequested data in between. This helps reduce the number of API calls
197+ * to remote storage services.
198+ *
199+ * This optimization is particularly useful when performing multiple small range reads
200+ * that are close to each other, as it reduces the overhead of multiple network requests
201+ * at the cost of transferring some additional data.
202+ */
203+ gap ?: bigint
204+ /**
205+ * Sets if-match condition for this operation.
206+ * If file exists and its etag doesn't match, an error will be returned.
207+ */
208+ ifMatch ?: string
209+ /**
210+ * Sets if-none-match condition for this operation.
211+ * If file exists and its etag matches, an error will be returned.
212+ */
213+ ifNoneMatch ?: string
214+ /**
215+ * Sets if-modified-since condition for this operation.
216+ * If file exists and hasn't been modified since the specified time, an error will be returned.
217+ * ISO 8601 formatted date string
218+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
219+ */
220+ ifModifiedSince ?: string
221+ /**
222+ * Sets if-unmodified-since condition for this operation.
223+ * If file exists and has been modified since the specified time, an error will be returned.
224+ * ISO 8601 formatted date string
225+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
226+ */
227+ ifUnmodifiedSince ?: string
228+ }
77229export const enum EntryMode {
78230 /** FILE means the path has data to read. */
79231 FILE = 0 ,
@@ -157,6 +309,12 @@ export class Capability {
157309 get statWithOverrideContentDisposition ( ) : boolean
158310 /** If operator supports read. */
159311 get read ( ) : boolean
312+ /** If operator supports read with version. */
313+ get readWithVersion ( ) : boolean
314+ /** If operator supports read with range. */
315+ get readWithIfModifiedSince ( ) : boolean
316+ /** If operator supports read with if unmodified since. */
317+ get readWithIfUnmodifiedSince ( ) : boolean
160318 /** If operator supports read with if matched. */
161319 get readWithIfMatch ( ) : boolean
162320 /** If operator supports read with if not match. */
@@ -332,13 +490,13 @@ export class Operator {
332490 * const buf = await op.read("path/to/file");
333491 * ```
334492 */
335- read ( path : string ) : Promise < Buffer >
493+ read ( path : string , options ?: ReadOptions | undefined | null ) : Promise < Buffer >
336494 /**
337495 * Create a reader to read the given path.
338496 *
339497 * It could be used to read large file in a streaming way.
340498 */
341- reader ( path : string ) : Promise < Reader >
499+ reader ( path : string , options ?: ReaderOptions | undefined | null ) : Promise < Reader >
342500 /**
343501 * Read the whole path into a buffer synchronously.
344502 *
@@ -347,13 +505,13 @@ export class Operator {
347505 * const buf = op.readSync("path/to/file");
348506 * ```
349507 */
350- readSync ( path : string ) : Buffer
508+ readSync ( path : string , options ?: ReadOptions | undefined | null ) : Buffer
351509 /**
352510 * Create a reader to read the given path synchronously.
353511 *
354512 * It could be used to read large file in a streaming way.
355513 */
356- readerSync ( path : string ) : BlockingReader
514+ readerSync ( path : string , options ?: ReaderOptions | undefined | null ) : BlockingReader
357515 /**
358516 * Write bytes into a path.
359517 *
0 commit comments