kassane commented on code in PR #5181:
URL: https://github.com/apache/opendal/pull/5181#discussion_r1810684116


##########
bindings/d/source/opendal/operator.d:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.
+ */
+
+module opendal.operator;
+
+import std.string: toStringz;
+import std.exception: enforce;
+import std.conv: to;
+import std.parallelism: task, TaskPool;
+
+/// OpenDAL-C binding for D. (unsafe/@system)
+private import opendal.opendal_c;
+
+struct Operator
+{
+    private opendal_operator* op;
+    private TaskPool taskPool;
+    private bool enabledParallelism;
+
+    this(string scheme, OperatorOptions options, bool useParallel = false) 
@trusted
+    {
+        auto result = opendal_operator_new(scheme.toStringz, options.options);
+        enforce(result.op !is null, "Failed to create Operator");
+        enforce(result.error is null, "Error in Operator");
+        op = result.op;
+        enabledParallelism = useParallel;
+
+        if (enabledParallelism)
+            taskPool = new TaskPool();
+    }
+
+    void write(string path, ubyte[] data) @trusted
+    {
+        opendal_bytes bytes = opendal_bytes(data.ptr, data.length, 
data.length);
+        auto error = opendal_operator_write(op, path.toStringz, &bytes);
+        enforce(error is null, "Error writing data");
+    }
+
+    void writeParallel(string path, ubyte[] data) @safe
+    {
+        auto t = task!((Operator* op, string p, ubyte[] d) { op.write(p, d); 
})(&this, path, data);
+        taskPool.put(t);
+        t.yieldForce();
+    }
+
+    ubyte[] readParallel(string path) @trusted
+    {
+        auto t = task!((Operator* op, string p) { return op.read(p); })(&this, 
path);
+        taskPool.put(t);
+        return t.yieldForce();
+    }
+
+    Entry[] listParallel(string path) @trusted
+    {
+        auto t = task!((Operator* op, string p) { return op.list(p); })(&this, 
path);
+        taskPool.put(t);
+        return t.yieldForce();
+    }
+
+    ubyte[] read(string path) @trusted
+    {
+        auto result = opendal_operator_read(op, path.toStringz);
+        enforce(result.error is null, "Error reading data");
+        scope (exit)
+            opendal_bytes_free(&result.data);
+        return result.data.data[0 .. result.data.len].dup;
+    }
+
+    void removeObject(string path) @trusted

Review Comment:
   Oh, I see! Sorry.
   Simplifying to `remove`.



-- 
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