JanKaul commented on code in PR #53:
URL: https://github.com/apache/iceberg-rust/pull/53#discussion_r1312698993


##########
crates/iceberg/src/io.rs:
##########
@@ -0,0 +1,116 @@
+// 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.
+
+//! This module contains io implementation.
+
+use crate::error::Result;
+use futures::{AsyncRead, AsyncSeek, AsyncWrite};
+use opendal::Operator;
+
+/// FileIO implementation.
+///
+/// This is a wrapper of opendal operator, which already provided an 
abstraction over all kinds of storage.
+pub struct FileIO {
+    op: Operator,
+}
+
+impl FileIO {
+    /// Creates from opendal operator.
+    pub fn new(op: Operator) -> Self {
+        Self { op }
+    }
+
+    /// Deletes file.
+    pub async fn delete(&self, path: impl AsRef<str>) -> Result<()> {
+        Ok(self.op.delete(path.as_ref()).await?)
+    }
+
+    /// Creates input file.
+    pub fn new_input(&self, path: impl Into<String>) -> Result<InputFile> {
+        Ok(InputFile {
+            op: self.op.clone(),
+            path: path.into(),
+        })
+    }
+
+    /// Creates output file.
+    pub fn new_output(&self, path: impl Into<String>) -> Result<OutputFile> {
+        Ok(OutputFile {
+            op: self.op.clone(),
+            path: path.into(),
+        })
+    }
+}
+
+/// Input file implementation.
+pub struct InputFile {
+    op: Operator,
+    path: String,
+}
+
+/// Input stream for reading.
+pub trait InputStream: AsyncRead + AsyncSeek {}
+
+impl<T> InputStream for T where T: AsyncRead + AsyncSeek {}
+
+impl InputFile {
+    /// Fully qualified of path.
+    pub fn location(&self) -> &str {
+        &self.path
+    }
+
+    /// Check if file exists.
+    pub async fn exists(&self) -> Result<bool> {
+        Ok(self.op.is_exist(&self.path).await?)
+    }
+
+    /// Returns [`opendal::Reader`] for reading.
+    pub async fn reader(&self) -> Result<impl InputStream> {
+        Ok(self.op.reader(&self.path).await?)
+    }
+}
+
+/// Output file implementation.
+pub struct OutputFile {
+    op: Operator,

Review Comment:
   Thankfully we have the expert here😉



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to