This is an automated email from the ASF dual-hosted git repository.

Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 60a64c16cb feat(bindings/nodejs): generate ReaderOptions from core 
(#9381)
60a64c16cb is described below

commit 60a64c16cb355f10d9de012208003ebe839a601b
Author: Chitral Verma <[email protected]>
AuthorDate: Sun Nov 29 19:41:08 2026 +0530

    feat(bindings/nodejs): generate ReaderOptions from core (#9381)
    
    * feat(bindings/nodejs): generate ReaderOptions from core
    
    Generate the Node.js ReaderOptions napi object, its JSDoc, and its
    conversion to core from the core ReaderOptions, as ReadOptions is. The
    members, types, optionality, and conversion stay as on main; prefetch
    keeps its u32 number that defaults to 0.
    
    Correct the core ReaderOptions docs: qualify NotFound by the option and
    capability checks, say that creating a reader does not access storage,
    and describe the default unchunked read, concurrent reads that need
    chunk, and the stat that a chunked open-ended or suffix read makes.
    
    Signed-off-by: Chitral Verma <[email protected]>
    
    * docs(core): correct the read_with and reader_with chunk and concurrent 
docs
    
    The FutureRead and FutureReader chunk and concurrent builders repeated
    the old ReadOptions text. Say that OpenDAL reads without chunks by
    default, that concurrent reads need chunk, and link chunk to the options
    docs that describe the stat a chunked read makes. The concurrent
    examples now set chunk, since concurrent alone has no effect.
    
    Signed-off-by: Chitral Verma <[email protected]>
    
    * docs: note that Reader::fetch reads concurrently without chunk
    
    Reader::fetch runs its merged ranges through concurrent tasks whether or
    not chunk is set, so the ReaderOptions::concurrent and
    FutureReader::concurrent docs now say that only fetch reads concurrently
    without chunk. Node.js has no fetch, so its docs keep saying that
    reader() and readerSync() do not read concurrently without chunk.
    
    The Node.js gap doc now says that readers read the whole file as one
    range, since chunked readers fetch chunks concurrently. The rewrite of
    "otherwise the read returns" is anchored to the chunk paragraph so the
    same words elsewhere stay as core wrote them.
    
    Signed-off-by: Chitral Verma <[email protected]>
    
    ---------
    
    Signed-off-by: Chitral Verma <[email protected]>
---
 .../java/org/apache/opendal/ReaderOptions.java     |   2 +
 bindings/nodejs/generated.d.ts                     | 129 ++++++--
 bindings/nodejs/src/options.rs                     | 114 +------
 bindings/nodejs/src/options/reader.rs              | 185 +++++++++++
 .../nodejs/tests/reader-options-surface.test.mjs   | 161 ++++++++++
 core/core/src/types/operator/operator_futures.rs   |  41 ++-
 core/core/src/types/options.rs                     |  34 +-
 dev/src/generate/nodejs.rs                         | 346 ++++++++++++++++++++-
 8 files changed, 849 insertions(+), 163 deletions(-)

diff --git a/bindings/java/src/main/java/org/apache/opendal/ReaderOptions.java 
b/bindings/java/src/main/java/org/apache/opendal/ReaderOptions.java
index e23383884f..7ccef6828b 100644
--- a/bindings/java/src/main/java/org/apache/opendal/ReaderOptions.java
+++ b/bindings/java/src/main/java/org/apache/opendal/ReaderOptions.java
@@ -123,6 +123,8 @@ public final class ReaderOptions {
      * Target size of each internal range request in bytes.
      *
      * <p>The default of {@code -1L} keeps unchunked streaming. Positive 
values enable chunked reads and must fit the native platform's unsigned 
pointer-sized integer. {@code 0L}, other negative values, and values that do 
not fit fail with {@link OpenDALException.Code#ConfigInvalid}.
+     *
+     * @see Capability#statWithIfModifiedSince
      */
     @Builder.Default
     public final long chunk = -1L;
diff --git a/bindings/nodejs/generated.d.ts b/bindings/nodejs/generated.d.ts
index 0f3425c467..a4e9ec7267 100644
--- a/bindings/nodejs/generated.d.ts
+++ b/bindings/nodejs/generated.d.ts
@@ -1324,30 +1324,69 @@ export interface PresignedRequest {
   headers: Record<string, string>
 }
 
+/**
+ * Options for reader operations.
+ *
+ * Each condition checks the file being read, and every condition must hold
+ * for the reader to produce data. Once the option and capability checks
+ * pass, a read that reaches storage fails with
+ * an error whose message includes `NotFound` for a missing file, no matter 
which
+ * conditions are set. An existing file that fails a condition produces
+ * an error whose message includes `ConditionNotMatch`, and a condition the 
service does
+ * not advertise through its capability returns
+ * an error whose message includes `Unsupported`; OpenDAL never silently drops 
a
+ * condition. Without a positive `chunk`, `reader()` and `readerSync()` check 
the
+ * options and capabilities without accessing storage, so a missing file or a
+ * failed condition surfaces when reading from the returned reader. With a
+ * positive `chunk`, they first stat the file, so either can fail `reader()`
+ * and `readerSync()` instead.
+ *
+ * See the [conditional operation 
specification](https://opendal.apache.org/docs/specifications/conditional-operations/)
+ * for the complete cross-operation contract.
+ */
 export interface ReaderOptions {
-  /** * Set `version` for this operation.
+  /**
+   * Read the given version of the file instead of the current one.
+   *
+   * This selects which stored version the reader returns; it is not a
+   * condition on the file. A version that does not exist produces
+   * an error whose message includes `NotFound`.
    *
-   * This option can be used to retrieve the data of a specified version of 
the given path.
+   * Check `Capability.readWithVersion` before using this
+   * option.
    */
   version?: string
-  /** * Set `concurrent` for the operation.
+  /**
+   * Set `concurrent` for the operation.
    *
-   * OpenDAL by default to read file without concurrent. This is not efficient 
for cases when users
-   * read large chunks of data. By setting `concurrent`, opendal will reading 
files concurrently
-   * on support storage services.
+   * OpenDAL reads a file without concurrency by default. This is not 
efficient for cases when users
+   * read large chunks of data. By setting `concurrent` together with `chunk`, 
opendal will read
+   * files concurrently on supported storage services.
    *
    * By setting `concurrent`, opendal will fetch chunks concurrently with
-   * the give chunk size.
+   * the given chunk size. Without `chunk`, `reader()` and `readerSync()` do 
not read concurrently.
    *
    * The value must be an integer between 0 and 4294967295.
    */
   concurrent?: number
-  /** * Sets the chunk size for this operation.
+  /**
+   * Set `chunk` for the operation.
+   *
+   * By default, OpenDAL reads each range with a single request instead of in 
chunks. Users can set
+   * chunk based on their own needs.
+   * `0` has the same behavior as omitting it.
    *
-   * OpenDAL will use services' preferred chunk size by default. Users can set 
chunk based on their own needs.
+   * `reader()` and `readerSync()` with a positive `chunk` first stat the file
+   * to learn its length.
+   * That stat carries the reader's version and conditions, so each of them
+   * also needs its stat capability, such as
+   * `Capability.statWithIfModifiedSince` for
+   * `ifModifiedSince`; otherwise creating the reader fails with
+   * an error whose message includes `Unsupported`.
    */
   chunk?: number
-  /** Controls the number of prefetched bytes ranges that can be buffered in 
memory
+  /**
+   * Controls the number of prefetched bytes ranges that can be buffered in 
memory
    * during concurrent reading.
    *
    * When performing concurrent reads with `Reader`, this option limits how 
many
@@ -1362,26 +1401,70 @@ export interface ReaderOptions {
    * concurrency settings.
    */
   prefetch?: number
-  /** Readers returned by `reader()` and `readerSync()` read sequentially, so 
`gap` has no effect. */
+  /**
+   * Readers returned by `reader()` and `readerSync()` read the whole file as 
one range, so
+   * `gap`, which merges nearby ranges, has no effect.
+   */
   gap?: bigint
-  /** * Sets if-match condition for this operation.
-   * If file exists and its etag doesn't match, an error will be returned.
+  /**
+   * Read only when the file has this exact ETag.
+   *
+   * The condition succeeds when the file exists and its ETag equals this
+   * value. A file with a different ETag produces
+   * an error whose message includes `ConditionNotMatch`; a missing file 
produces
+   * an error whose message includes `NotFound`. Only concrete ETag values are
+   * portable; a wildcard such as `"*"` has no portable meaning here.
+   *
+   * The operation returns an error whose message includes `Unsupported` when 
the
+   * service does not advertise `Capability.readWithIfMatch`.
    */
   ifMatch?: string
-  /** * Sets if-none-match condition for this operation.
-   * If file exists and its etag matches, an error will be returned.
+  /**
+   * Read only when the file does not have this ETag.
+   *
+   * With a concrete ETag value, the condition succeeds when the file
+   * exists with a different ETag. A file whose ETag equals this value
+   * produces an error whose message includes `ConditionNotMatch`; a missing 
file
+   * produces an error whose message includes `NotFound`. Only concrete ETag 
values
+   * are portable; a wildcard such as `"*"` has no portable meaning here.
+   *
+   * The operation returns an error whose message includes `Unsupported` when 
the
+   * service does not advertise
+   * `Capability.readWithIfNoneMatch`.
    */
   ifNoneMatch?: string
-  /** * Sets if-modified-since condition for this operation.
-   * If file exists and hasn't been modified since the specified time, an 
error will be returned.
-   * ISO 8601 formatted date string
-   * 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
+  /**
+   * Read only when the file was modified after this timestamp.
+   *
+   * The condition succeeds when the file exists and was modified after
+   * this time. A file not modified since this time produces
+   * an error whose message includes `ConditionNotMatch`; a missing file 
produces
+   * an error whose message includes `NotFound`.
+   *
+   * The operation returns an error whose message includes `Unsupported` when 
the
+   * service does not advertise
+   * `Capability.readWithIfModifiedSince`.
+   *
+   * Pass an ISO 8601 string, such as `2024-01-01T00:00:00Z` or the result
+   * of `Date.prototype.toISOString()`. A string that does not parse fails
+   * the operation.
    */
   ifModifiedSince?: string
-  /** * Sets if-unmodified-since condition for this operation.
-   * If file exists and has been modified since the specified time, an error 
will be returned.
-   * ISO 8601 formatted date string
-   * 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
+  /**
+   * Read only when the file was not modified after this timestamp.
+   *
+   * The condition succeeds when the file exists and was not modified
+   * after this time. A file modified after this time produces
+   * an error whose message includes `ConditionNotMatch`; a missing file 
produces
+   * an error whose message includes `NotFound`.
+   *
+   * The operation returns an error whose message includes `Unsupported` when 
the
+   * service does not advertise
+   * `Capability.readWithIfUnmodifiedSince`.
+   *
+   * Pass an ISO 8601 string, such as `2024-01-01T00:00:00Z` or the result
+   * of `Date.prototype.toISOString()`. A string that does not parse fails
+   * the operation.
    */
   ifUnmodifiedSince?: string
 }
diff --git a/bindings/nodejs/src/options.rs b/bindings/nodejs/src/options.rs
index bd5e3b3321..ddf2000698 100644
--- a/bindings/nodejs/src/options.rs
+++ b/bindings/nodejs/src/options.rs
@@ -26,10 +26,12 @@ use crate::validate::parse_count;
 mod delete;
 mod list;
 mod read;
+mod reader;
 mod stat;
 pub use delete::DeleteOptions;
 pub use list::ListOptions;
 pub use read::ReadOptions;
+pub use reader::ReaderOptions;
 pub use stat::StatOptions;
 
 /// Convert a JavaScript `BigInt` into a `u64` offset or size.
@@ -84,118 +86,6 @@ fn parse_timestamp(value: &str, field: &str) -> 
napi::Result<Timestamp> {
     })
 }
 
-#[napi(object)]
-#[derive(Default)]
-pub struct ReaderOptions {
-    /**
-     * Set `version` for this operation.
-     *
-     * This option can be used to retrieve the data of a specified version of 
the given path.
-     */
-    pub version: Option<String>,
-
-    /**
-     * Set `concurrent` for the operation.
-     *
-     * OpenDAL by default to read file without concurrent. This is not 
efficient for cases when users
-     * read large chunks of data. By setting `concurrent`, opendal will 
reading files concurrently
-     * on support storage services.
-     *
-     * By setting `concurrent`, opendal will fetch chunks concurrently with
-     * the give chunk size.
-     *
-     * The value must be an integer between 0 and 4294967295.
-     */
-    pub concurrent: Option<f64>,
-
-    /**
-     * Sets the chunk size for this operation.
-     *
-     * OpenDAL will use services' preferred chunk size by default. Users can 
set chunk based on their own needs.
-     */
-    pub chunk: Option<u32>,
-
-    /** Controls the number of prefetched bytes ranges that can be buffered in 
memory
-     * during concurrent reading.
-     *
-     * When performing concurrent reads with `Reader`, this option limits how 
many
-     * completed-but-not-yet-read chunks can be buffered. Once the number of 
buffered
-     * chunks reaches this limit, no new read tasks will be spawned until some 
of the
-     * buffered chunks are consumed.
-     *
-     * - Default value: 0 (no prefetching, strict back-pressure control)
-     * - Set to a higher value to allow more aggressive prefetching at the 
cost of memory
-     *
-     * This option helps prevent memory exhaustion when reading large files 
with high
-     * concurrency settings.
-     */
-    pub prefetch: Option<u32>,
-
-    /// Readers returned by `reader()` and `readerSync()` read sequentially, 
so `gap` has no effect.
-    pub gap: Option<BigInt>,
-
-    /**
-     * Sets if-match condition for this operation.
-     * If file exists and its etag doesn't match, an error will be returned.
-     */
-    pub if_match: Option<String>,
-
-    /**
-     * Sets if-none-match condition for this operation.
-     * If file exists and its etag matches, an error will be returned.
-     */
-    pub if_none_match: Option<String>,
-
-    /**
-     * Sets if-modified-since condition for this operation.
-     * If file exists and hasn't been modified since the specified time, an 
error will be returned.
-     * ISO 8601 formatted date string
-     * 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
-     */
-    pub if_modified_since: Option<String>,
-
-    /**
-     * Sets if-unmodified-since condition for this operation.
-     * If file exists and has been modified since the specified time, an error 
will be returned.
-     * ISO 8601 formatted date string
-     * 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
-     */
-    pub if_unmodified_since: Option<String>,
-}
-
-impl TryFrom<ReaderOptions> for opendal::options::ReaderOptions {
-    type Error = napi::Error;
-
-    fn try_from(value: ReaderOptions) -> napi::Result<Self> {
-        let if_modified_since = value
-            .if_modified_since
-            .map(|v| parse_timestamp(&v, "ifModifiedSince"))
-            .transpose()?;
-        let if_unmodified_since = value
-            .if_unmodified_since
-            .map(|v| parse_timestamp(&v, "ifUnmodifiedSince"))
-            .transpose()?;
-        let concurrent = value
-            .concurrent
-            .map(|v| parse_count(v, "concurrent", 0))
-            .transpose()?
-            .unwrap_or_default();
-        Ok(Self {
-            version: value.version,
-            concurrent,
-            chunk: value.chunk.map(|chunk| chunk as usize),
-            gap: value.gap.map(|gap| gap.get_u64().1 as usize),
-            prefetch: value.prefetch.unwrap_or_default() as usize,
-            if_match: value.if_match,
-            if_none_match: value.if_none_match,
-            if_modified_since,
-            if_unmodified_since,
-            content_length_hint: None,
-            ..Default::default()
-        })
-    }
-}
-
 #[napi(object)]
 #[derive(Default, Debug)]
 pub struct WriteOptions {
diff --git a/bindings/nodejs/src/options/reader.rs 
b/bindings/nodejs/src/options/reader.rs
new file mode 100644
index 0000000000..3b316f9838
--- /dev/null
+++ b/bindings/nodejs/src/options/reader.rs
@@ -0,0 +1,185 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// DO NOT EDIT IT MANUALLY. This file is generated by 
opendal/dev/src/generate/nodejs.rs.
+
+/// Options for reader operations.
+///
+/// Each condition checks the file being read, and every condition must hold
+/// for the reader to produce data. Once the option and capability checks
+/// pass, a read that reaches storage fails with
+/// an error whose message includes `NotFound` for a missing file, no matter 
which
+/// conditions are set. An existing file that fails a condition produces
+/// an error whose message includes `ConditionNotMatch`, and a condition the 
service does
+/// not advertise through its capability returns
+/// an error whose message includes `Unsupported`; OpenDAL never silently 
drops a
+/// condition. Without a positive `chunk`, `reader()` and `readerSync()` check 
the
+/// options and capabilities without accessing storage, so a missing file or a
+/// failed condition surfaces when reading from the returned reader. With a
+/// positive `chunk`, they first stat the file, so either can fail `reader()`
+/// and `readerSync()` instead.
+///
+/// See the [conditional operation 
specification](https://opendal.apache.org/docs/specifications/conditional-operations/)
+/// for the complete cross-operation contract.
+#[napi(object)]
+#[derive(Debug, Default)]
+pub struct ReaderOptions {
+    /// Read the given version of the file instead of the current one.
+    ///
+    /// This selects which stored version the reader returns; it is not a
+    /// condition on the file. A version that does not exist produces
+    /// an error whose message includes `NotFound`.
+    ///
+    /// Check `Capability.readWithVersion` before using this
+    /// option.
+    pub version: Option<String>,
+
+    /// Set `concurrent` for the operation.
+    ///
+    /// OpenDAL reads a file without concurrency by default. This is not 
efficient for cases when users
+    /// read large chunks of data. By setting `concurrent` together with 
`chunk`, opendal will read
+    /// files concurrently on supported storage services.
+    ///
+    /// By setting `concurrent`, opendal will fetch chunks concurrently with
+    /// the given chunk size. Without `chunk`, `reader()` and `readerSync()` 
do not read concurrently.
+    ///
+    /// The value must be an integer between 0 and 4294967295.
+    pub concurrent: Option<f64>,
+
+    /// Set `chunk` for the operation.
+    ///
+    /// By default, OpenDAL reads each range with a single request instead of 
in chunks. Users can set
+    /// chunk based on their own needs.
+    /// `0` has the same behavior as omitting it.
+    ///
+    /// `reader()` and `readerSync()` with a positive `chunk` first stat the 
file
+    /// to learn its length.
+    /// That stat carries the reader's version and conditions, so each of them
+    /// also needs its stat capability, such as
+    /// `Capability.statWithIfModifiedSince` for
+    /// `ifModifiedSince`; otherwise creating the reader fails with
+    /// an error whose message includes `Unsupported`.
+    pub chunk: Option<u32>,
+
+    /// Controls the number of prefetched bytes ranges that can be buffered in 
memory
+    /// during concurrent reading.
+    ///
+    /// When performing concurrent reads with `Reader`, this option limits how 
many
+    /// completed-but-not-yet-read chunks can be buffered. Once the number of 
buffered
+    /// chunks reaches this limit, no new read tasks will be spawned until 
some of the
+    /// buffered chunks are consumed.
+    ///
+    /// - Default value: 0 (no prefetching, strict back-pressure control)
+    /// - Set to a higher value to allow more aggressive prefetching at the 
cost of memory
+    ///
+    /// This option helps prevent memory exhaustion when reading large files 
with high
+    /// concurrency settings.
+    pub prefetch: Option<u32>,
+
+    /// Readers returned by `reader()` and `readerSync()` read the whole file 
as one range, so
+    /// `gap`, which merges nearby ranges, has no effect.
+    pub gap: Option<napi::bindgen_prelude::BigInt>,
+
+    /// Read only when the file has this exact ETag.
+    ///
+    /// The condition succeeds when the file exists and its ETag equals this
+    /// value. A file with a different ETag produces
+    /// an error whose message includes `ConditionNotMatch`; a missing file 
produces
+    /// an error whose message includes `NotFound`. Only concrete ETag values 
are
+    /// portable; a wildcard such as `"*"` has no portable meaning here.
+    ///
+    /// The operation returns an error whose message includes `Unsupported` 
when the
+    /// service does not advertise `Capability.readWithIfMatch`.
+    pub if_match: Option<String>,
+
+    /// Read only when the file does not have this ETag.
+    ///
+    /// With a concrete ETag value, the condition succeeds when the file
+    /// exists with a different ETag. A file whose ETag equals this value
+    /// produces an error whose message includes `ConditionNotMatch`; a 
missing file
+    /// produces an error whose message includes `NotFound`. Only concrete 
ETag values
+    /// are portable; a wildcard such as `"*"` has no portable meaning here.
+    ///
+    /// The operation returns an error whose message includes `Unsupported` 
when the
+    /// service does not advertise
+    /// `Capability.readWithIfNoneMatch`.
+    pub if_none_match: Option<String>,
+
+    /// Read only when the file was modified after this timestamp.
+    ///
+    /// The condition succeeds when the file exists and was modified after
+    /// this time. A file not modified since this time produces
+    /// an error whose message includes `ConditionNotMatch`; a missing file 
produces
+    /// an error whose message includes `NotFound`.
+    ///
+    /// The operation returns an error whose message includes `Unsupported` 
when the
+    /// service does not advertise
+    /// `Capability.readWithIfModifiedSince`.
+    ///
+    /// Pass an ISO 8601 string, such as `2024-01-01T00:00:00Z` or the result
+    /// of `Date.prototype.toISOString()`. A string that does not parse fails
+    /// the operation.
+    pub if_modified_since: Option<String>,
+
+    /// Read only when the file was not modified after this timestamp.
+    ///
+    /// The condition succeeds when the file exists and was not modified
+    /// after this time. A file modified after this time produces
+    /// an error whose message includes `ConditionNotMatch`; a missing file 
produces
+    /// an error whose message includes `NotFound`.
+    ///
+    /// The operation returns an error whose message includes `Unsupported` 
when the
+    /// service does not advertise
+    /// `Capability.readWithIfUnmodifiedSince`.
+    ///
+    /// Pass an ISO 8601 string, such as `2024-01-01T00:00:00Z` or the result
+    /// of `Date.prototype.toISOString()`. A string that does not parse fails
+    /// the operation.
+    pub if_unmodified_since: Option<String>,
+}
+
+impl TryFrom<ReaderOptions> for opendal::options::ReaderOptions {
+    type Error = napi::Error;
+
+    fn try_from(value: ReaderOptions) -> napi::Result<Self> {
+        Ok(Self {
+            version: value.version,
+            if_match: value.if_match,
+            if_none_match: value.if_none_match,
+            if_version_match: Default::default(),
+            if_version_not_match: Default::default(),
+            if_modified_since: value
+                .if_modified_since
+                .map(|v| super::parse_timestamp(&v, "ifModifiedSince"))
+                .transpose()?,
+            if_unmodified_since: value
+                .if_unmodified_since
+                .map(|v| super::parse_timestamp(&v, "ifUnmodifiedSince"))
+                .transpose()?,
+            content_length_hint: Default::default(),
+            concurrent: value
+                .concurrent
+                .map(|v| crate::validate::parse_count(v, "concurrent", 0))
+                .transpose()?
+                .unwrap_or_default(),
+            chunk: value.chunk.map(|v| v as usize),
+            gap: value.gap.map(|v| v.get_u64().1 as usize),
+            prefetch: value.prefetch.unwrap_or_default() as usize,
+            checksum: Default::default(),
+        })
+    }
+}
diff --git a/bindings/nodejs/tests/reader-options-surface.test.mjs 
b/bindings/nodejs/tests/reader-options-surface.test.mjs
new file mode 100644
index 0000000000..c3c38e5edf
--- /dev/null
+++ b/bindings/nodejs/tests/reader-options-surface.test.mjs
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { readFileSync } from 'node:fs'
+import path from 'node:path'
+
+import { assert, describe, expect, test } from 'vitest'
+
+import { Operator } from '../index.mjs'
+
+const content = '0123456789abcdef'
+
+// `ReaderOptions` and the reader methods as `generated.d.ts` declared them
+// before `ReaderOptions` was generated from core. Callers pass these options
+// as object literals or implement the interface structurally, so each member
+// must stay with its type and stay optional, and a new member must be added
+// here on purpose.
+//
+// Each member comes with a value of its type and the core option it sets.
+// When core checks a capability for that option, the capability is listed
+// too, and a service without it must reject the reader naming the core
+// option. Otherwise the reader must return the whole file.
+const FROZEN_MEMBERS = [
+  ['version?: string', 'v1', 'version', 'readWithVersion'],
+  ['concurrent?: number', 4, 'concurrent', null],
+  ['chunk?: number', 3, 'chunk', null],
+  ['prefetch?: number', 2, 'prefetch', null],
+  ['gap?: bigint', 1n, 'gap', null],
+  ['ifMatch?: string', '"etag"', 'if_match', 'readWithIfMatch'],
+  ['ifNoneMatch?: string', '"etag"', 'if_none_match', 'readWithIfNoneMatch'],
+  ['ifModifiedSince?: string', new Date(0).toISOString(), 'if_modified_since', 
'readWithIfModifiedSince'],
+  ['ifUnmodifiedSince?: string', '2100-01-01T00:00:00Z', 
'if_unmodified_since', 'readWithIfUnmodifiedSince'],
+]
+
+const FROZEN_SIGNATURES = [
+  'reader(path: string, options?: ReaderOptions | undefined | null): 
Promise<Reader>',
+  'readerSync(path: string, options?: ReaderOptions | undefined | null): 
BlockingReader',
+]
+
+const READERS = [
+  ['reader', async (op, path, options) => op.reader(path, options)],
+  ['readerSync', async (op, path, options) => op.readerSync(path, options)],
+]
+
+// Read a `Reader` or `BlockingReader` to its end.
+async function readAll(reader) {
+  const chunks = []
+  for (;;) {
+    const buf = Buffer.alloc(5)
+    const n = Number(await reader.read(buf))
+    if (n === 0) {
+      return Buffer.concat(chunks).toString()
+    }
+    chunks.push(buf.subarray(0, n))
+  }
+}
+
+function declared(kind, name) {
+  const dts = readFileSync(path.resolve(__dirname, '../generated.d.ts'), 
'utf8')
+  const body = dts.match(new RegExp(`^export ${kind} ${name} 
\\{\\n([\\s\\S]*?)^\\}`, 'm'))
+  assert.ok(body, `generated.d.ts declares ${kind} ${name}`)
+  return body[1]
+    .split('\n')
+    .filter((line) => /^ {2}\w/.test(line))
+    .map((line) => line.trim())
+}
+
+describe('ReaderOptions keeps its historical surface', () => {
+  const op = new Operator('memory')
+  const file = 'reader-options-surface'
+  const missing = `${file}-missing`
+  op.writeSync(file, content)
+
+  test('declares exactly the frozen members', () => {
+    assert.sameMembers(
+      declared('interface', 'ReaderOptions'),
+      FROZEN_MEMBERS.map(([member]) => member),
+    )
+  })
+
+  for (const signature of FROZEN_SIGNATURES) {
+    test(signature, () => {
+      assert.include(declared('declare class', 'Operator'), signature)
+    })
+  }
+
+  for (const [member, value, coreOption, capability] of FROZEN_MEMBERS) {
+    const [, field] = member.match(/^(\w+)\?: /)
+    const options = { [field]: value }
+
+    for (const [method, open] of READERS) {
+      test(`${method} with ${member}`, async () => {
+        if (capability === null || op.capability()[capability]) {
+          // The reader accepts a value of the declared type.
+          assert.equal(await readAll(await open(op, file, options)), content)
+        } else {
+          // The option reaches core as `coreOption`, which this service does
+          // not support.
+          const unsupported = new RegExp(
+            `^Unsupported \\(permanent\\) at read\\b.* with the arguments 
${coreOption}\\.`,
+          )
+          await expect(open(op, file, 
options)).rejects.toThrowError(unsupported)
+        }
+      })
+    }
+  }
+
+  for (const [method, open] of READERS) {
+    test(`${method} reads with chunk, concurrent, and prefetch, and converts 
chunk and gap as main did`, async () => {
+      // Which `concurrent` and `prefetch` reach core is not observable on
+      // memory; the generator test `test_reader_options_conversion` pins
+      // their conversion.
+      assert.equal(await readAll(await open(op, file, { chunk: 0, concurrent: 
0, prefetch: 0 })), content)
+      assert.equal(await readAll(await open(op, file, { chunk: 4, concurrent: 
2, prefetch: 1 })), content)
+      // `chunk` reaches core: only a reader with a positive `chunk` stats the
+      // file before it returns, and a zero `chunk` reads as if it were
+      // omitted.
+      await expect(open(op, missing, { chunk: 4 
})).rejects.toThrowError(/^NotFound \(permanent\) at stat\b/)
+      for (const options of [{}, { chunk: 0 }]) {
+        const reader = await open(op, missing, options)
+        await expect(readAll(reader)).rejects.toThrowError(/^NotFound 
\(permanent\) at read\b/)
+      }
+      // `gap` ignores its sign and the bits above 64, as main did.
+      assert.equal(await readAll(await open(op, file, { gap: -1n })), content)
+      assert.equal(await readAll(await open(op, file, { gap: 1n << 64n })), 
content)
+    })
+
+    test(`${method} rejects invalid values in main's order`, async () => {
+      const invalid = {
+        ifModifiedSince: 'not-a-date',
+        ifUnmodifiedSince: 'not-a-date',
+        concurrent: 1.5,
+      }
+      for (const [field, message] of [
+        ['ifModifiedSince', 'ifModifiedSince must be an ISO 8601 timestamp'],
+        ['ifUnmodifiedSince', 'ifUnmodifiedSince must be an ISO 8601 
timestamp'],
+        ['concurrent', 'concurrent must be an integer between 0 and 
4294967295'],
+      ]) {
+        await expect(open(op, file, invalid)).rejects.toThrowError(message)
+        delete invalid[field]
+      }
+      assert.deepEqual(invalid, {})
+    })
+  }
+})
diff --git a/core/core/src/types/operator/operator_futures.rs 
b/core/core/src/types/operator/operator_futures.rs
index 742c246b3f..d86cfd1ff7 100644
--- a/core/core/src/types/operator/operator_futures.rs
+++ b/core/core/src/types/operator/operator_futures.rs
@@ -332,18 +332,22 @@ impl<F: Future<Output = Result<Buffer>>> FutureRead<F> {
 
     /// Set `concurrent` for the reader.
     ///
-    /// OpenDAL by default to write file without concurrent. This is not 
efficient for cases when users
-    /// read large chunks of data. By setting `concurrent`, opendal will read 
files concurrently
-    /// on support storage services.
+    /// OpenDAL reads a file without concurrency by default. This is not 
efficient for cases when users
+    /// read large chunks of data. By setting `concurrent` together with 
`chunk`, opendal will read
+    /// files concurrently on supported storage services.
     ///
     /// By setting `concurrent`, opendal will fetch chunks concurrently with
-    /// the given chunk size.
+    /// the given chunk size. Without `chunk`, OpenDAL does not read 
concurrently.
     ///
     /// ```
     /// # use opendal_core::Result;
     /// # use opendal_core::Operator;
     /// # async fn test(op: Operator) -> Result<()> {
-    /// let r = op.read_with("path/to/file").concurrent(8).await?;
+    /// let r = op
+    ///     .read_with("path/to/file")
+    ///     .chunk(4 * 1024 * 1024)
+    ///     .concurrent(8)
+    ///     .await?;
     /// # Ok(())
     /// # }
     /// ```
@@ -352,9 +356,13 @@ impl<F: Future<Output = Result<Buffer>>> FutureRead<F> {
         self
     }
 
-    /// OpenDAL will use services' preferred chunk size by default. Users can 
set chunk based on their own needs.
+    /// By default, OpenDAL reads the range with a single request instead of 
in chunks. Users can set chunk
+    /// based on their own needs.
     /// Pass `0` to use the default read behavior without an explicit chunk 
size.
     ///
+    /// Refer to [`options::ReadOptions::chunk`] for the full contract, 
including when a chunked
+    /// read first stats the file.
+    ///
     /// This following example will make opendal read data in 4MiB chunks:
     ///
     /// ```
@@ -516,18 +524,23 @@ impl<F: Future<Output = Result<Reader>>> FutureReader<F> {
 
     /// Set `concurrent` for the reader.
     ///
-    /// OpenDAL by default to write file without concurrent. This is not 
efficient for cases when users
-    /// read large chunks of data. By setting `concurrent`, opendal will 
reading files concurrently
-    /// on support storage services.
+    /// OpenDAL reads a file without concurrency by default. This is not 
efficient for cases when users
+    /// read large chunks of data. By setting `concurrent` together with 
`chunk`, opendal will read
+    /// files concurrently on supported storage services.
     ///
     /// By setting `concurrent`, opendal will fetch chunks concurrently with
-    /// the give chunk size.
+    /// the given chunk size. Without `chunk`, only [`Reader::fetch`]
+    /// reads concurrently, with one request per merged range.
     ///
     /// ```
     /// # use opendal_core::Result;
     /// # use opendal_core::Operator;
     /// # async fn test(op: Operator) -> Result<()> {
-    /// let r = op.reader_with("path/to/file").concurrent(8).await?;
+    /// let r = op
+    ///     .reader_with("path/to/file")
+    ///     .chunk(4 * 1024 * 1024)
+    ///     .concurrent(8)
+    ///     .await?;
     /// # Ok(())
     /// # }
     /// ```
@@ -536,9 +549,13 @@ impl<F: Future<Output = Result<Reader>>> FutureReader<F> {
         self
     }
 
-    /// OpenDAL will use services' preferred chunk size by default. Users can 
set chunk based on their own needs.
+    /// By default, OpenDAL reads each range with a single request instead of 
in chunks. Users can set
+    /// chunk based on their own needs.
     /// Pass `0` to use the default read behavior without an explicit chunk 
size.
     ///
+    /// Refer to [`options::ReaderOptions::chunk`] for the full contract, 
including when a chunked
+    /// read first stats the file.
+    ///
     /// This following example will make opendal read data in 4MiB chunks:
     ///
     /// ```
diff --git a/core/core/src/types/options.rs b/core/core/src/types/options.rs
index 2e789079b2..5137b3d16d 100644
--- a/core/core/src/types/options.rs
+++ b/core/core/src/types/options.rs
@@ -395,14 +395,16 @@ pub struct ReadOptions {
 /// Options for reader operations.
 ///
 /// Each condition checks the file being read, and every condition must hold
-/// for the reader to produce data. A missing file fails with
-/// [`crate::ErrorKind::NotFound`] no matter which conditions are set. An
-/// existing file that fails a condition returns
+/// for the reader to produce data. Once the option and capability checks
+/// pass, a read that reaches storage fails with
+/// [`crate::ErrorKind::NotFound`] for a missing file, no matter which
+/// conditions are set. An existing file that fails a condition returns
 /// [`crate::ErrorKind::ConditionNotMatch`], and a condition the service does
 /// not advertise through its capability returns
 /// [`crate::ErrorKind::Unsupported`]; OpenDAL never silently drops a
-/// condition. Depending on the service, a conditional error may surface when
-/// creating the reader or while reading from it.
+/// condition. Creating the reader checks the options and capabilities
+/// without accessing storage, so a missing file or a failed condition
+/// surfaces when reading from it.
 ///
 /// See the [conditional operation 
specification][crate::docs::specs::conditional_operations]
 /// for the complete cross-operation contract.
@@ -495,21 +497,33 @@ pub struct ReaderOptions {
 
     /// Set `concurrent` for the operation.
     ///
-    /// OpenDAL by default to read file without concurrent. This is not 
efficient for cases when users
-    /// read large chunks of data. By setting `concurrent`, opendal will 
reading files concurrently
-    /// on support storage services.
+    /// OpenDAL reads a file without concurrency by default. This is not 
efficient for cases when users
+    /// read large chunks of data. By setting `concurrent` together with 
`chunk`, opendal will read
+    /// files concurrently on supported storage services.
     ///
     /// By setting `concurrent`, opendal will fetch chunks concurrently with
-    /// the give chunk size.
+    /// the given chunk size. Without `chunk`, only [`crate::Reader::fetch`]
+    /// reads concurrently, with one request per merged range.
     ///
     /// Refer to the [performance 
guide](https://github.com/apache/opendal/tree/main/core/core/src/docs/performance)
     /// for more details.
     pub concurrent: usize,
     /// Set `chunk` for the operation.
     ///
-    /// OpenDAL will use services' preferred chunk size by default. Users can 
set chunk based on their own needs.
+    /// By default, OpenDAL reads each range with a single request instead of 
in chunks. Users can set
+    /// chunk based on their own needs.
     /// `Some(0)` has the same behavior as `None`.
     ///
+    /// A read with a positive `chunk` and an open-ended or suffix range first
+    /// stats the file to learn its length, unless `content_length_hint` is set
+    /// or an earlier read from this reader observed the length. Unlike with
+    /// [`ReadOptions::chunk`], an empty suffix range also stats the file.
+    /// That stat carries the reader's version and conditions, so each of them
+    /// also needs its stat capability, such as
+    /// [`crate::Capability::stat_with_if_modified_since`] for
+    /// `if_modified_since`; otherwise the read returns
+    /// [`crate::ErrorKind::Unsupported`].
+    ///
     /// Refer to the [performance 
guide](https://github.com/apache/opendal/tree/main/core/core/src/docs/performance)
     /// for more details.
     pub chunk: Option<usize>,
diff --git a/dev/src/generate/nodejs.rs b/dev/src/generate/nodejs.rs
index b85f5ec17a..709c966f00 100644
--- a/dev/src/generate/nodejs.rs
+++ b/dev/src/generate/nodejs.rs
@@ -193,8 +193,9 @@ struct JsOptions {
     /// `offset` and `size` members of a `range` need one.
     docs: &'static [(&'static str, &'static [&'static str])],
     /// Node.js wording for rendered core doc text that does not hold for the
-    /// JS methods, as `(rendered text, JS text)`. Generation fails when one
-    /// matches nothing, so a reworded core doc gets reviewed again.
+    /// JS methods, as `(rendered text, JS text)`, with core's line breaks as
+    /// `\n`. Generation fails when one matches nothing, so a reworded core doc
+    /// gets reviewed again.
     rewrites: &'static [(&'static str, &'static str)],
 }
 
@@ -212,6 +213,8 @@ enum Js {
     /// A `usize` count as a `number` that `parse_count` checks. An omitted
     /// value is `0`.
     Count,
+    /// A `usize` as a `number` read as `u32`. An omitted value is `0`.
+    U32OrZero,
     /// An `Option<usize>` as a `bigint` read with `BigInt::get_u64`, which
     /// ignores the sign and the bits above 64.
     LossyBigInt,
@@ -229,7 +232,7 @@ impl Js {
             Js::String => OptionKind::OptionString,
             Js::Bool => OptionKind::Bool,
             Js::U32 | Js::LossyBigInt => OptionKind::OptionUsize,
-            Js::Count => OptionKind::Usize,
+            Js::Count | Js::U32OrZero => OptionKind::Usize,
             Js::Timestamp => OptionKind::OptionTimestamp,
             Js::OffsetSize => OptionKind::BytesRange,
         }
@@ -356,6 +359,72 @@ const READ_OPTIONS: JsOptions = JsOptions {
     ],
 };
 
+const READER_OPTIONS: JsOptions = JsOptions {
+    name: "ReaderOptions",
+    module: "reader",
+    fields: &[
+        ("version", Js::String),
+        ("concurrent", Js::Count),
+        ("chunk", Js::U32),
+        ("prefetch", Js::U32OrZero),
+        ("gap", Js::LossyBigInt),
+        ("if_match", Js::String),
+        ("if_none_match", Js::String),
+        ("if_modified_since", Js::Timestamp),
+        ("if_unmodified_since", Js::Timestamp),
+    ],
+    renamed: &[],
+    // Core documents how `Reader::fetch` merges ranges, which JS does not
+    // expose.
+    docs: &[(
+        "gap",
+        &[
+            "Readers returned by `reader()` and `readerSync()` read the whole 
file as one range, so",
+            "`gap`, which merges nearby ranges, has no effect.",
+        ],
+    )],
+    // `reader()` and `readerSync()` read the whole file, without a suffix
+    // range, `content_length_hint`, or `Reader::fetch`, so a positive `chunk`
+    // makes them stat the file before they return.
+    rewrites: &[
+        (
+            concat!(
+                "Without `chunk`, only `crate::Reader::fetch`\n",
+                "reads concurrently, with one request per merged range.",
+            ),
+            "Without `chunk`, `reader()` and `readerSync()` do not read 
concurrently.",
+        ),
+        (
+            concat!(
+                "Creating the reader checks the options and capabilities\n",
+                "without accessing storage, so a missing file or a failed 
condition\n",
+                "surfaces when reading from it.",
+            ),
+            concat!(
+                "Without a positive `chunk`, `reader()` and `readerSync()` 
check the\n",
+                "options and capabilities without accessing storage, so a 
missing file or a\n",
+                "failed condition surfaces when reading from the returned 
reader. With a\n",
+                "positive `chunk`, they first stat the file, so either can 
fail `reader()`\n",
+                "and `readerSync()` instead.",
+            ),
+        ),
+        (
+            concat!(
+                "A read with a positive `chunk` and an open-ended or suffix 
range first\n",
+                "stats the file to learn its length, unless 
`content_length_hint` is set\n",
+                "or an earlier read from this reader observed the length. 
Unlike with\n",
+                "`ReadOptions::chunk`, an empty suffix range also stats the 
file.",
+            ),
+            "`reader()` and `readerSync()` with a positive `chunk` first stat 
the file\n\
+             to learn its length.",
+        ),
+        (
+            "`ifModifiedSince`; otherwise the read returns",
+            "`ifModifiedSince`; otherwise creating the reader fails with",
+        ),
+    ],
+};
+
 /// Render model for one field of a napi options object.
 #[derive(Serialize)]
 struct OptionsField {
@@ -386,7 +455,13 @@ fn generate_options(workspace_dir: &Path) -> Result<()> {
 
     let dir = workspace_dir.join("bindings/nodejs/src/options");
     fs::create_dir_all(&dir)?;
-    for options in [&LIST_OPTIONS, &STAT_OPTIONS, &DELETE_OPTIONS, 
&READ_OPTIONS] {
+    for options in [
+        &LIST_OPTIONS,
+        &STAT_OPTIONS,
+        &DELETE_OPTIONS,
+        &READ_OPTIONS,
+        &READER_OPTIONS,
+    ] {
         let rendered = render_options(&parsed, options, &capabilities)?;
         fs::write(
             dir.join(format!("{}.rs", options.module)),
@@ -562,6 +637,10 @@ fn js_type(name: &str, form: Js) -> JsType {
             fallible: true,
             note: &["The value must be an integer between 0 and 4294967295."],
         },
+        Js::U32OrZero => infallible(
+            "Option<u32>",
+            format!("value.{name}.unwrap_or_default() as usize"),
+        ),
         Js::LossyBigInt => infallible(
             "Option<napi::bindgen_prelude::BigInt>",
             format!("value.{name}.map(|v| v.get_u64().1 as usize)"),
@@ -827,8 +906,13 @@ mod tests {
         doc
     }
 
-    const ALL_OPTIONS: [&JsOptions; 4] =
-        [&LIST_OPTIONS, &STAT_OPTIONS, &DELETE_OPTIONS, &READ_OPTIONS];
+    const ALL_OPTIONS: [&JsOptions; 5] = [
+        &LIST_OPTIONS,
+        &STAT_OPTIONS,
+        &DELETE_OPTIONS,
+        &READ_OPTIONS,
+        &READER_OPTIONS,
+    ];
 
     #[test]
     fn test_options_new_core_field_is_not_exposed() {
@@ -891,6 +975,14 @@ mod tests {
             );
         }
 
+        let mut missing = core_options("ReaderOptions");
+        missing.fields.retain(|field| field.name != "prefetch");
+        let err = render(missing, &READER_OPTIONS).unwrap_err().to_string();
+        assert!(
+            err.contains("ReaderOptions has no field `prefetch`"),
+            "{err}"
+        );
+
         // A kind change must fail, whether or not JS supports the new kind:
         // `limit` must not change its JS type, `startAfter` must not turn
         // into a boolean, `ifModifiedSince` must keep being parsed, and the
@@ -960,6 +1052,38 @@ mod tests {
                 OptionKind::Bool,
                 "ReadOptions::override_cache_control is Bool",
             ),
+            // The reader `prefetch` must stay a `number` that defaults to
+            // `0`, and the other reader fields keep their read types.
+            (
+                &READER_OPTIONS,
+                "prefetch",
+                OptionKind::OptionUsize,
+                "ReaderOptions::prefetch is OptionUsize",
+            ),
+            (
+                &READER_OPTIONS,
+                "concurrent",
+                OptionKind::OptionUsize,
+                "ReaderOptions::concurrent is OptionUsize",
+            ),
+            (
+                &READER_OPTIONS,
+                "chunk",
+                OptionKind::Usize,
+                "ReaderOptions::chunk is Usize",
+            ),
+            (
+                &READER_OPTIONS,
+                "gap",
+                OptionKind::OptionU64,
+                "ReaderOptions::gap is OptionU64",
+            ),
+            (
+                &READER_OPTIONS,
+                "if_unmodified_since",
+                OptionKind::OptionString,
+                "ReaderOptions::if_unmodified_since is OptionString",
+            ),
         ] {
             let mut changed = core_options(options.name);
             let field = changed.fields.iter_mut().find(|f| f.name == 
name).unwrap();
@@ -993,6 +1117,100 @@ mod tests {
             ),
             "{err}"
         );
+
+        let mut reworded = core_options("ReaderOptions");
+        let chunk = reworded
+            .fields
+            .iter_mut()
+            .find(|f| f.name == "chunk")
+            .unwrap();
+        for line in &mut chunk.doc {
+            *line = line.replace(
+                "otherwise the read returns",
+                "otherwise the read fails with",
+            );
+        }
+        let err = render(reworded, &READER_OPTIONS).unwrap_err().to_string();
+        assert!(
+            err.contains(
+                "ReaderOptions docs no longer contain \
+                 ``ifModifiedSince`; otherwise the read returns`"
+            ),
+            "{err}"
+        );
+
+        // A rewrite only changes the text it was written for, so the same
+        // words in another member's doc stay as core wrote them.
+        let mut other = core_options("ReaderOptions");
+        let version = other
+            .fields
+            .iter_mut()
+            .find(|f| f.name == "version")
+            .unwrap();
+        version
+            .doc
+            .push("Check it first; otherwise the read returns 
early.".to_string());
+        let rendered = render(other, &READER_OPTIONS).unwrap();
+        let version = field_doc(&rendered, "version").join(" ");
+        assert!(
+            version.ends_with("Check it first; otherwise the read returns 
early."),
+            "{version}"
+        );
+    }
+
+    #[test]
+    fn test_reader_options_docs_use_node_wording() {
+        let rendered = render(core_options("ReaderOptions"), 
&READER_OPTIONS).unwrap();
+        let struct_text = rendered[..rendered.find("#[napi(object)]").unwrap()]
+            .lines()
+            .filter_map(|line| line.strip_prefix("///"))
+            .map(str::trim)
+            .collect::<Vec<_>>()
+            .join(" ");
+        // Without a positive `chunk`, `reader()` and `readerSync()` do not
+        // access storage; with one, they stat the file first.
+        for expected in [
+            "Once the option and capability checks pass, a read that reaches 
storage fails with \
+             an error whose message includes `NotFound` for a missing file",
+            "condition. Without a positive `chunk`, `reader()` and 
`readerSync()` check the \
+             options and capabilities without accessing storage, so a missing 
file or a failed \
+             condition surfaces when reading from the returned reader. With a 
positive `chunk`, \
+             they first stat the file, so either can fail `reader()` and 
`readerSync()` instead.",
+        ] {
+            assert!(struct_text.contains(expected), "{struct_text}");
+        }
+        let concurrent = field_doc(&rendered, "concurrent").join(" ");
+        assert!(
+            concurrent.contains(
+                "the given chunk size. Without `chunk`, `reader()` and 
`readerSync()` do not read \
+                 concurrently."
+            ),
+            "{concurrent}"
+        );
+        let chunk = field_doc(&rendered, "chunk").join(" ");
+        for expected in [
+            "`reader()` and `readerSync()` with a positive `chunk` first stat 
the file to learn \
+             its length.",
+            "such as `Capability.statWithIfModifiedSince` for 
`ifModifiedSince`; otherwise \
+             creating the reader fails with an error whose message includes 
`Unsupported`.",
+        ] {
+            assert!(chunk.contains(expected), "{chunk}");
+        }
+        let docs: String = rendered
+            .lines()
+            .filter(|line| line.trim_start().starts_with("///"))
+            .collect();
+        for rust in [
+            "suffix",
+            "content_length_hint",
+            "ReadOptions::chunk",
+            "earlier read",
+            "Creating the reader",
+            "the read returns",
+            "Reader::fetch",
+        ] {
+            assert!(!docs.contains(rust), "ReaderOptions docs contain 
`{rust}`");
+        }
     }
 
     #[test]
@@ -1125,6 +1343,26 @@ mod tests {
                     "checksum",
                 ][..],
             ),
+            (
+                &READER_OPTIONS,
+                &[
+                    "version: Option<String>,",
+                    "concurrent: Option<f64>,",
+                    "chunk: Option<u32>,",
+                    "prefetch: Option<u32>,",
+                    "gap: Option<napi::bindgen_prelude::BigInt>,",
+                    "if_match: Option<String>,",
+                    "if_none_match: Option<String>,",
+                    "if_modified_since: Option<String>,",
+                    "if_unmodified_since: Option<String>,",
+                ][..],
+                &[
+                    "if_version_match",
+                    "if_version_not_match",
+                    "content_length_hint",
+                    "checksum",
+                ][..],
+            ),
         ] {
             let name = options.name;
             let rendered = render(core_options(name), options).unwrap();
@@ -1202,6 +1440,53 @@ mod tests {
         assert!(order.is_sorted(), "{order:?}");
     }
 
+    #[test]
+    fn test_reader_options_conversion() {
+        let rendered = render(core_options("ReaderOptions"), 
&READER_OPTIONS).unwrap();
+        assert!(
+            rendered.contains("impl TryFrom<ReaderOptions> for 
opendal::options::ReaderOptions {")
+        );
+        // The conversion on main: the timestamps must parse, `concurrent`
+        // must be a count, `chunk` and `prefetch` are read as `u32`, an
+        // omitted `prefetch` is `0`, and `gap` drops its sign and high bits.
+        for line in [
+            "            version: value.version,\n",
+            "            if_match: value.if_match,\n",
+            "            if_none_match: value.if_none_match,\n",
+            concat!(
+                "            if_modified_since: value\n",
+                "                .if_modified_since\n",
+                "                .map(|v| super::parse_timestamp(&v, 
\"ifModifiedSince\"))\n",
+                "                .transpose()?,\n",
+            ),
+            concat!(
+                "            if_unmodified_since: value\n",
+                "                .if_unmodified_since\n",
+                "                .map(|v| super::parse_timestamp(&v, 
\"ifUnmodifiedSince\"))\n",
+                "                .transpose()?,\n",
+            ),
+            concat!(
+                "            concurrent: value\n",
+                "                .concurrent\n",
+                "                .map(|v| crate::validate::parse_count(v, 
\"concurrent\", 0))\n",
+                "                .transpose()?\n",
+                "                .unwrap_or_default(),\n",
+            ),
+            "            chunk: value.chunk.map(|v| v as usize),\n",
+            "            gap: value.gap.map(|v| v.get_u64().1 as usize),\n",
+            "            prefetch: value.prefetch.unwrap_or_default() as 
usize,\n",
+        ] {
+            assert!(rendered.contains(line), "{line}");
+        }
+        // Main converts the timestamps first, then `concurrent`, so a call
+        // with several invalid values reports the same one.
+        let order: Vec<usize> = ["if_modified_since:", "if_unmodified_since:", 
"concurrent:"]
+            .iter()
+            .map(|field| rendered.find(&format!("            {field} 
")).unwrap())
+            .collect();
+        assert!(order.is_sorted(), "{order:?}");
+    }
+
     #[test]
     fn test_options_conversion_parses_timestamps() {
         let stat = render(core_options("StatOptions"), &STAT_OPTIONS).unwrap();
@@ -1495,6 +1780,20 @@ mod tests {
                     ),
                 ][..],
             ),
+            (
+                &READER_OPTIONS,
+                &[
+                    ("version", "`Capability.readWithVersion`"),
+                    ("if_match", "`Capability.readWithIfMatch`"),
+                    ("if_none_match", "`Capability.readWithIfNoneMatch`"),
+                    ("if_modified_since", 
"`Capability.readWithIfModifiedSince`"),
+                    (
+                        "if_unmodified_since",
+                        "`Capability.readWithIfUnmodifiedSince`",
+                    ),
+                    ("chunk", "`Capability.statWithIfModifiedSince`"),
+                ][..],
+            ),
         ] {
             let rendered = render(core_options(options.name), 
options).unwrap();
             for (name, capability) in expected {
@@ -1620,6 +1919,33 @@ mod tests {
                      cannot request one.",
                 ),
             ],
+            "ReaderOptions" => &[
+                (
+                    "Without `chunk`, only `crate::Reader::fetch` reads 
concurrently, with one \
+                     request per merged range.",
+                    "Without `chunk`, `reader()` and `readerSync()` do not 
read concurrently.",
+                ),
+                (
+                    "Creating the reader checks the options and capabilities 
without accessing \
+                     storage, so a missing file or a failed condition surfaces 
when reading from it.",
+                    "Without a positive `chunk`, `reader()` and `readerSync()` 
check the options and \
+                     capabilities without accessing storage, so a missing file 
or a failed condition \
+                     surfaces when reading from the returned reader. With a 
positive `chunk`, they \
+                     first stat the file, so either can fail `reader()` and 
`readerSync()` instead.",
+                ),
+                (
+                    "A read with a positive `chunk` and an open-ended or 
suffix range first stats \
+                     the file to learn its length, unless 
`content_length_hint` is set or an \
+                     earlier read from this reader observed the length. Unlike 
with \
+                     `ReadOptions::chunk`, an empty suffix range also stats 
the file.",
+                    "`reader()` and `readerSync()` with a positive `chunk` 
first stat the file to \
+                     learn its length.",
+                ),
+                (
+                    "`ifModifiedSince`; otherwise the read returns",
+                    "`ifModifiedSince`; otherwise creating the reader fails 
with",
+                ),
+            ],
             _ => &[],
         };
         paragraphs
@@ -1649,6 +1975,14 @@ mod tests {
                    has no effect.",
                 ],
             ),
+            (
+                "ReaderOptions",
+                "gap",
+                &[
+                    "Readers returned by `reader()` and `readerSync()` read 
the whole file as one \
+                     range, so `gap`, which merges nearby ranges, has no 
effect.",
+                ],
+            ),
             (
                 "ReadOptions",
                 "offset",

Reply via email to