Xuanwo commented on code in PR #6564:
URL: https://github.com/apache/opendal/pull/6564#discussion_r2615157633


##########
core/src/services/opfs/reader.rs:
##########
@@ -0,0 +1,139 @@
+// 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.
+
+use std::sync::Arc;
+use std::u64;
+
+use bytes::{Bytes, BytesMut};
+use futures::channel::{mpsc, oneshot};
+use futures::{SinkExt, StreamExt};
+use js_sys::Uint8Array;
+use wasm_bindgen::JsCast;
+use wasm_bindgen_futures::JsFuture;
+use web_sys::{File, ReadableStreamDefaultReader, ReadableStreamReadResult};
+
+use crate::raw::{oio, OpRead};
+use crate::*;
+
+use super::core::OpfsCore;
+use super::error::parse_js_error;
+
+enum ReadRequest {
+    Read { tx: oneshot::Sender<Result<Bytes>> },
+}
+
+pub struct OpfsReader {
+    pos: usize,
+    end_pos: usize,
+    tx: mpsc::UnboundedSender<ReadRequest>,
+}
+
+impl OpfsReader {
+    pub async fn new(core: Arc<OpfsCore>, path: &str, op: &OpRead) -> 
Result<Self> {
+        let pos = op.range().offset();
+        let end_pos = op
+            .range()
+            .size()
+            .map(|sz| pos + sz)
+            .unwrap_or(i32::MAX as u64);
+
+        let file_handle = core.file_handle(path).await?;
+        let file: File = JsFuture::from(file_handle.get_file())
+            .await
+            .and_then(JsCast::dyn_into)
+            .map_err(parse_js_error)?;
+
+        let read_stream = file
+            .slice_with_i32_and_i32(pos as i32, end_pos as i32)
+            .map_err(parse_js_error)?
+            .stream()
+            .get_reader()
+            .dyn_into::<ReadableStreamDefaultReader>()
+            .map_err(|obj| parse_js_error(obj.into()))?;
+
+        let (tx, rx) = mpsc::unbounded();
+
+        // everything in wasm-bindgen is non-send, so we need to spawn a new 
task

Review Comment:
   > I think we can remove read/write/list from this PR for now and open a new 
issue on how to implememt these without using channel. What do you think 
@Xuanwo ?
   
   Sorry for the late. And this plan looks good to me



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to