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

suyanhanx pushed a commit to branch gdrive-docs
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit c610776e9ed74e5546b9d9e825e3c94e4716156c
Author: suyanhanx <[email protected]>
AuthorDate: Tue Aug 29 20:55:15 2023 +0800

    support range read
    
    Signed-off-by: suyanhanx <[email protected]>
---
 core/src/services/gdrive/backend.rs |  7 ++++---
 core/src/services/gdrive/core.rs    | 15 +++++++++++++--
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/core/src/services/gdrive/backend.rs 
b/core/src/services/gdrive/backend.rs
index da6f950b3..69949287c 100644
--- a/core/src/services/gdrive/backend.rs
+++ b/core/src/services/gdrive/backend.rs
@@ -53,6 +53,7 @@ impl Accessor for GdriveBackend {
                 stat: true,
 
                 read: true,
+                read_with_range: true,
 
                 write: true,
 
@@ -131,7 +132,7 @@ impl Accessor for GdriveBackend {
         }
     }
 
-    async fn read(&self, path: &str, _args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
+    async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
         // We need to request for metadata and body separately here.
         // Request for metadata first to check if the file exists.
         let resp = self.core.gdrive_stat(path).await?;
@@ -143,12 +144,12 @@ impl Accessor for GdriveBackend {
                 let body = resp.into_body().bytes().await?;
                 let meta = self.parse_metadata(body)?;
 
-                let resp = self.core.gdrive_get(path).await?;
+                let resp = self.core.gdrive_get(path, args).await?;
 
                 let status = resp.status();
 
                 match status {
-                    StatusCode::OK => Ok((RpRead::with_metadata(meta), 
resp.into_body())),
+                    StatusCode::OK | StatusCode::PARTIAL_CONTENT => 
Ok((RpRead::with_metadata(meta), resp.into_body())),
                     _ => Err(parse_error(resp).await?),
                 }
             }
diff --git a/core/src/services/gdrive/core.rs b/core/src/services/gdrive/core.rs
index 24ff1cf89..b0ea944fb 100644
--- a/core/src/services/gdrive/core.rs
+++ b/core/src/services/gdrive/core.rs
@@ -305,13 +305,24 @@ impl GdriveCore {
         self.client.send(req).await
     }
 
-    pub async fn gdrive_get(&self, path: &str) -> 
Result<Response<IncomingAsyncBody>> {
+    pub async fn gdrive_get(
+        &self,
+        path: &str,
+        args: OpRead,
+    ) -> Result<Response<IncomingAsyncBody>> {
         let url: String = format!(
             "https://www.googleapis.com/drive/v3/files/{}?alt=media";,
             self.get_file_id_by_path(path).await?
         );
 
-        let mut req = Request::get(&url)
+        let mut req = Request::get(&url);
+
+        let range = args.range();
+        if !range.is_full() {
+            req = req.header(header::RANGE, range.to_header());
+        }
+
+        let mut req = req
             .body(AsyncBody::Empty)
             .map_err(new_request_build_error)?;
         self.sign(&mut req).await?;

Reply via email to