kassane commented on code in PR #5181: URL: https://github.com/apache/opendal/pull/5181#discussion_r1803510727
########## bindings/d/source/opendal/operator.d: ########## @@ -0,0 +1,199 @@ +/* + * 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; + +/// OpenDAL-C binding for D. (unsafe/@system) +private import opendal.opendal_c; + +struct OpenDAL +{ + private opendal_operator* op; + + this(string scheme, OpenDALOptions options) @trusted + { + auto result = opendal_operator_new(scheme.toStringz, options.options); + enforce(result.op !is null, "Failed to create OpenDAL operator"); + enforce(result.error is null, "Error in OpenDAL operator"); + op = result.op; + } + + void writeData(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"); + } + + ubyte[] readData(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 deleteObject(string path) @trusted Review Comment: in D2 `delete` isn't keyword, (replaced to `destroy`): https://dlang.org/spec/expression.html#DeleteExpression -- 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]
