-
Notifications
You must be signed in to change notification settings - Fork 723
Expand file tree
/
Copy pathopendal.h
More file actions
1598 lines (1520 loc) · 47.6 KB
/
opendal.h
File metadata and controls
1598 lines (1520 loc) · 47.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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.
*/
#ifndef _OPENDAL_H
#define _OPENDAL_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#define OPENDAL_SEEK_SET 0
#define OPENDAL_SEEK_CUR 1
#define OPENDAL_SEEK_END 2
/**
* \brief The error code for all opendal APIs in C binding.
* \todo The error handling is not complete, the error with error message will be
* added in the future.
*/
typedef enum opendal_code {
/**
* returning it back. For example, s3 returns an internal service error.
*/
OPENDAL_UNEXPECTED,
/**
* Underlying service doesn't support this operation.
*/
OPENDAL_UNSUPPORTED,
/**
* The config for backend is invalid.
*/
OPENDAL_CONFIG_INVALID,
/**
* The given path is not found.
*/
OPENDAL_NOT_FOUND,
/**
* The given path doesn't have enough permission for this operation
*/
OPENDAL_PERMISSION_DENIED,
/**
* The given path is a directory.
*/
OPENDAL_IS_A_DIRECTORY,
/**
* The given path is not a directory.
*/
OPENDAL_NOT_A_DIRECTORY,
/**
* The given path already exists thus we failed to the specified operation on it.
*/
OPENDAL_ALREADY_EXISTS,
/**
* Requests that sent to this path is over the limit, please slow down.
*/
OPENDAL_RATE_LIMITED,
/**
* The given file paths are same.
*/
OPENDAL_IS_SAME_FILE,
/**
* The condition of this operation is not match.
*/
OPENDAL_CONDITION_NOT_MATCH,
/**
* The range of the content is not satisfied.
*/
OPENDAL_RANGE_NOT_SATISFIED,
} opendal_code;
/**
* \brief opendal_bytes carries raw-bytes with its length
*
* The opendal_bytes type is a C-compatible substitute for Vec type
* in Rust, it has to be manually freed. You have to call opendal_bytes_free()
* to free the heap memory to avoid memory leak.
*
* @see opendal_bytes_free
*/
typedef struct opendal_bytes {
/**
* Pointing to the byte array on heap
*/
uint8_t *data;
/**
* The length of the byte array
*/
uintptr_t len;
/**
* The capacity of the byte array
*/
uintptr_t capacity;
} opendal_bytes;
/**
* \brief The opendal error type for C binding, containing an error code and corresponding error
* message.
*
* The normal operations returns a pointer to the opendal_error, and the **nullptr normally
* represents no error has taken placed**. If any error has taken place, the caller should check
* the error code and print the error message.
*
* The error code is represented in opendal_code, which is an enum on different type of errors.
* The error messages is represented in opendal_bytes, which is a non-null terminated byte array.
*
* \note 1. The error message is on heap, so the error needs to be freed by the caller, by calling
* opendal_error_free. 2. The error message is not null terminated, so the caller should
* never use "%s" to print the error message.
*
* @see opendal_code
* @see opendal_bytes
* @see opendal_error_free
*/
typedef struct opendal_error {
enum opendal_code code;
struct opendal_bytes message;
} opendal_error;
/**
* \brief opendal_list_entry is the entry under a path, which is listed from the opendal_lister
*
* For examples, please see the comment section of opendal_operator_list()
* @see opendal_operator_list()
* @see opendal_list_entry_path()
* @see opendal_list_entry_name()
*/
typedef struct opendal_entry {
/**
* The pointer to the opendal::Entry in the Rust code.
* Only touch this on judging whether it is NULL.
*/
void *inner;
} opendal_entry;
/**
* \brief The result type returned by opendal_lister_next().
* The list entry is the list result of the list operation, the error field is the error code and error message.
* If the operation succeeds, the error should be NULL.
*
* \note Please notice if the lister reaches the end, both the list_entry and error will be NULL.
*/
typedef struct opendal_result_lister_next {
/**
* The next object name
*/
struct opendal_entry *entry;
/**
* The error, if ok, it is null
*/
struct opendal_error *error;
} opendal_result_lister_next;
/**
* \brief BlockingLister is designed to list entries at given path in a blocking
* manner.
*
* Users can construct Lister by `blocking_list` or `blocking_scan`(currently not supported in C binding)
*
* For examples, please see the comment section of opendal_operator_list()
* @see opendal_operator_list()
*/
typedef struct opendal_lister {
/**
* The pointer to the opendal::BlockingLister in the Rust code.
* Only touch this on judging whether it is NULL.
*/
void *inner;
} opendal_lister;
/**
* \brief Carries all metadata associated with a **path**.
*
* The metadata of the "thing" under a path. Please **only** use the opendal_metadata
* with our provided API, e.g. opendal_metadata_content_length().
*
* \note The metadata is also heap-allocated, please call opendal_metadata_free() on this
* to free the heap memory.
*
* @see opendal_metadata_free
*/
typedef struct opendal_metadata {
/**
* The pointer to the opendal::Metadata in the Rust code.
* Only touch this on judging whether it is NULL.
*/
void *inner;
} opendal_metadata;
/**
* \brief Used to access almost all OpenDAL APIs. It represents an
* operator that provides the unified interfaces provided by OpenDAL.
*
* @see opendal_operator_new This function construct the operator
* @see opendal_operator_free This function frees the heap memory of the operator
*
* \note The opendal_operator actually owns a pointer to
* an opendal::blocking::Operator, which is inside the Rust core code.
*
* \remark You may use the field `ptr` to check whether this is a NULL
* operator.
*/
typedef struct opendal_operator {
/**
* The pointer to the opendal::blocking::Operator in the Rust code.
* Only touch this on judging whether it is NULL.
*/
void *inner;
} opendal_operator;
/**
* \brief The result type returned by opendal_operator_new() operation.
*
* If the init logic is successful, the `op` field will be set to a valid
* pointer, and the `error` field will be set to null. If the init logic fails, the
* `op` field will be set to null, and the `error` field will be set to a
* valid pointer with error code and error message.
*
* @see opendal_operator_new()
* @see opendal_operator
* @see opendal_error
*/
typedef struct opendal_result_operator_new {
/**
* The pointer for operator.
*/
struct opendal_operator *op;
/**
* The error pointer for error.
*/
struct opendal_error *error;
} opendal_result_operator_new;
/**
* \brief The configuration for the initialization of opendal_operator.
*
* \note This is also a heap-allocated struct, please free it after you use it
*
* @see opendal_operator_new has an example of using opendal_operator_options
* @see opendal_operator_options_new This function construct the operator
* @see opendal_operator_options_free This function frees the heap memory of the operator
* @see opendal_operator_options_set This function allow you to set the options
*/
typedef struct opendal_operator_options {
/**
* The pointer to the HashMap<String, String> in the Rust code.
* Only touch this on judging whether it is NULL.
*/
void *inner;
} opendal_operator_options;
/**
* \brief The result type returned by opendal's read operation.
*
* The result type of read operation in opendal C binding, it contains
* the data that the read operation returns and an NULL error.
* If the read operation failed, the `data` fields should be a nullptr
* and the error is not NULL.
*/
typedef struct opendal_result_read {
/**
* The byte array with length returned by read operations
*/
struct opendal_bytes data;
/**
* The error, if ok, it is null
*/
struct opendal_error *error;
} opendal_result_read;
/**
* \brief The result type returned by opendal's reader operation.
*
* \note The opendal_reader actually owns a pointer to
* a opendal::BlockingReader, which is inside the Rust core code.
*/
typedef struct opendal_reader {
/**
* The pointer to the opendal::StdReader in the Rust code.
* Only touch this on judging whether it is NULL.
*/
void *inner;
} opendal_reader;
/**
* \brief The result type returned by opendal_operator_reader().
* The result type for opendal_operator_reader(), the field `reader` contains the reader
* of the path, which is an iterator of the objects under the path. the field `code` represents
* whether the stat operation is successful.
*/
typedef struct opendal_result_operator_reader {
/**
* The pointer for opendal_reader
*/
struct opendal_reader *reader;
/**
* The error, if ok, it is null
*/
struct opendal_error *error;
} opendal_result_operator_reader;
/**
* \brief The result type returned by opendal's writer operation.
* \note The opendal_writer actually owns a pointer to
* an opendal::blocking::Writer, which is inside the Rust core code.
*/
typedef struct opendal_writer {
/**
* The pointer to the opendal::blocking::Writer in the Rust code.
* Only touch this on judging whether it is NULL.
*/
void *inner;
} opendal_writer;
/**
* \brief The result type returned by opendal_operator_writer().
* The result type for opendal_operator_writer(), the field `writer` contains the writer
* of the path, which is an iterator of the objects under the path. the field `code` represents
*/
typedef struct opendal_result_operator_writer {
/**
* The pointer for opendal_writer
*/
struct opendal_writer *writer;
/**
* The error, if ok, it is null
*/
struct opendal_error *error;
} opendal_result_operator_writer;
/**
* \brief Options for read operations used by C side.
*
* \note For detail description of each field, please refer to [`core::ReadOptions`]
*/
typedef struct opendal_operator_options_read {
/**
* Set `range` for this operation.
*/
const uint64_t *range;
/**
* Set `version` for this operation.
*/
const char *version;
/**
* Set `if_match` for this operation.
*/
const char *if_match;
/**
* Set `if_none_match` for this operation.
*/
const char *if_none_match;
/**
* Set `if_modified_since` for this operation.
*
* \note The value should be in RFC 3339 format.
*/
const char *if_modified_since;
/**
* Set `if_unmodified_since` for this operation.
*
* \note The value should be in RFC 3339 format.
*/
const char *if_unmodified_since;
/**
* Set `concurrent` for the operation.
*
* \note for we do not provide default value in C, so it must be Option in C side.
*/
const uintptr_t *concurrent;
/**
* Set `chunk` for the operation.
*/
const uintptr_t *chunk;
/**
* Controls the optimization strategy for range reads in [`Reader::fetch`].
*/
const uintptr_t *gap;
/**
* Specify the content-type header that should be sent back by the operation.
*/
const char *override_content_type;
/**
* Specify the `cache-control` header that should be sent back by the operation.
*/
const char *override_cache_control;
/**
* Specify the `content-disposition` header that should be sent back by the operation.
*/
const char *override_content_disposition;
} opendal_operator_options_read;
/**
* \brief The result type returned by opendal_operator_is_exist().
*
* The result type for opendal_operator_is_exist(), the field `is_exist`
* contains whether the path exists, and the field `error` contains the
* corresponding error. If successful, the `error` field is null.
*
* \note If the opendal_operator_is_exist() fails, the `is_exist` field
* will be set to false.
*/
typedef struct opendal_result_is_exist {
/**
* Whether the path exists
*/
bool is_exist;
/**
* The error, if ok, it is null
*/
struct opendal_error *error;
} opendal_result_is_exist;
/**
* \brief The result type returned by opendal_operator_exists().
*
* The result type for opendal_operator_exists(), the field `exists`
* contains whether the path exists, and the field `error` contains the
* corresponding error. If successful, the `error` field is null.
*
* \note If the opendal_operator_exists() fails, the `exists` field
* will be set to false.
*/
typedef struct opendal_result_exists {
/**
* Whether the path exists
*/
bool exists;
/**
* The error, if ok, it is null
*/
struct opendal_error *error;
} opendal_result_exists;
/**
* \brief The result type returned by opendal_operator_stat().
*
* The result type for opendal_operator_stat(), the field `meta` contains the metadata
* of the path, the field `error` represents whether the stat operation is successful.
* If successful, the `error` field is null.
*/
typedef struct opendal_result_stat {
/**
* The metadata output of the stat
*/
struct opendal_metadata *meta;
/**
* The error, if ok, it is null
*/
struct opendal_error *error;
} opendal_result_stat;
/**
* \brief The result type returned by opendal_operator_list().
*
* The result type for opendal_operator_list(), the field `lister` contains the lister
* of the path, which is an iterator of the objects under the path. the field `error` represents
* whether the stat operation is successful. If successful, the `error` field is null.
*/
typedef struct opendal_result_list {
/**
* The lister, used for further listing operations
*/
struct opendal_lister *lister;
/**
* The error, if ok, it is null
*/
struct opendal_error *error;
} opendal_result_list;
/**
* \brief Metadata for **operator**, users can use this metadata to get information
* of operator.
*/
typedef struct opendal_operator_info {
/**
* The pointer to the opendal::OperatorInfo in the Rust code.
* Only touch this on judging whether it is NULL.
*/
void *inner;
} opendal_operator_info;
/**
* \brief Capability is used to describe what operations are supported
* by current Operator.
*/
typedef struct opendal_capability {
/**
* If operator supports stat.
*/
bool stat;
/**
* If operator supports stat with if match.
*/
bool stat_with_if_match;
/**
* If operator supports stat with if none match.
*/
bool stat_with_if_none_match;
/**
* If operator supports read.
*/
bool read;
/**
* If operator supports read with if match.
*/
bool read_with_if_match;
/**
* If operator supports read with if none match.
*/
bool read_with_if_none_match;
/**
* if operator supports read with override cache control.
*/
bool read_with_override_cache_control;
/**
* if operator supports read with override content disposition.
*/
bool read_with_override_content_disposition;
/**
* if operator supports read with override content type.
*/
bool read_with_override_content_type;
/**
* If operator supports write.
*/
bool write;
/**
* If operator supports write can be called in multi times.
*/
bool write_can_multi;
/**
* If operator supports write with empty content.
*/
bool write_can_empty;
/**
* If operator supports write by append.
*/
bool write_can_append;
/**
* If operator supports write with content type.
*/
bool write_with_content_type;
/**
* If operator supports write with content disposition.
*/
bool write_with_content_disposition;
/**
* If operator supports write with cache control.
*/
bool write_with_cache_control;
/**
* write_multi_max_size is the max size that services support in write_multi.
*
* For example, AWS S3 supports 5GiB as max in write_multi.
*
* If it is not set, this will be zero
*/
uintptr_t write_multi_max_size;
/**
* write_multi_min_size is the min size that services support in write_multi.
*
* For example, AWS S3 requires at least 5MiB in write_multi expect the last one.
*
* If it is not set, this will be zero
*/
uintptr_t write_multi_min_size;
/**
* write_total_max_size is the max size that services support in write_total.
*
* For example, Cloudflare D1 supports 1MB as max in write_total.
*
* If it is not set, this will be zero
*/
uintptr_t write_total_max_size;
/**
* If operator supports create dir.
*/
bool create_dir;
/**
* If operator supports delete.
*/
bool delete_;
/**
* If operator supports copy.
*/
bool copy;
/**
* If operator supports rename.
*/
bool rename;
/**
* If operator supports list.
*/
bool list;
/**
* If backend supports list with limit.
*/
bool list_with_limit;
/**
* If backend supports list with start after.
*/
bool list_with_start_after;
/**
* If backend supports list without delimiter.
*/
bool list_with_recursive;
/**
* If operator supports presign.
*/
bool presign;
/**
* If operator supports presign read.
*/
bool presign_read;
/**
* If operator supports presign stat.
*/
bool presign_stat;
/**
* If operator supports presign write.
*/
bool presign_write;
/**
* If operator supports shared.
*/
bool shared;
} opendal_capability;
/**
* \brief The is the result type returned by opendal_reader_read().
* The result type contains a size field, which is the size of the data read,
* which is zero on error. The error field is the error code and error message.
*/
typedef struct opendal_result_reader_read {
/**
* The read size if succeed.
*/
uintptr_t size;
/**
* The error, if ok, it is null
*/
struct opendal_error *error;
} opendal_result_reader_read;
/**
* \brief The result type returned by opendal_reader_seek().
* The result type contains a pos field, which is the new position after seek,
* which is zero on error. The error field is the error code and error message.
*/
typedef struct opendal_result_reader_seek {
/**
* New position after seek
*/
uint64_t pos;
/**
* The error, if ok, it is null
*/
struct opendal_error *error;
} opendal_result_reader_seek;
/**
* \brief The result type returned by opendal_writer_write().
* The result type contains a size field, which is the size of the data written,
* which is zero on error. The error field is the error code and error message.
*/
typedef struct opendal_result_writer_write {
/**
* The write size if succeed.
*/
uintptr_t size;
/**
* The error, if ok, it is null
*/
struct opendal_error *error;
} opendal_result_writer_write;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/**
* \brief Frees the opendal_error, ok to call on NULL
*/
void opendal_error_free(struct opendal_error *ptr);
/**
* \brief Return the next object to be listed
*
* Lister is an iterator of the objects under its path, this method is the same as
* calling next() on the iterator
*
* For examples, please see the comment section of opendal_operator_list()
* @see opendal_operator_list()
*/
struct opendal_result_lister_next opendal_lister_next(struct opendal_lister *self);
/**
* \brief Free the heap-allocated metadata used by opendal_lister
*/
void opendal_lister_free(struct opendal_lister *ptr);
/**
* \brief Free the heap-allocated metadata used by opendal_metadata
*/
void opendal_metadata_free(struct opendal_metadata *ptr);
/**
* \brief Return the content_length of the metadata
*
* # Example
* ```C
* // ... previously you wrote "Hello, World!" to path "/testpath"
* opendal_result_stat s = opendal_operator_stat(op, "/testpath");
* assert(s.error == NULL);
*
* opendal_metadata *meta = s.meta;
* assert(opendal_metadata_content_length(meta) == 13);
* ```
*/
uint64_t opendal_metadata_content_length(const struct opendal_metadata *self);
/**
* \brief Return whether the path represents a file
*
* # Example
* ```C
* // ... previously you wrote "Hello, World!" to path "/testpath"
* opendal_result_stat s = opendal_operator_stat(op, "/testpath");
* assert(s.error == NULL);
*
* opendal_metadata *meta = s.meta;
* assert(opendal_metadata_is_file(meta));
* ```
*/
bool opendal_metadata_is_file(const struct opendal_metadata *self);
/**
* \brief Return whether the path represents a directory
*
* # Example
* ```C
* // ... previously you wrote "Hello, World!" to path "/testpath"
* opendal_result_stat s = opendal_operator_stat(op, "/testpath");
* assert(s.error == NULL);
*
* opendal_metadata *meta = s.meta;
*
* // this is not a directory
* assert(!opendal_metadata_is_dir(meta));
* ```
*
* \todo This is not a very clear example. A clearer example will be added
* after we support opendal_operator_mkdir()
*/
bool opendal_metadata_is_dir(const struct opendal_metadata *self);
/**
* \brief Return the last_modified of the metadata, in milliseconds
*
* # Example
* ```C
* // ... previously you wrote "Hello, World!" to path "/testpath"
* opendal_result_stat s = opendal_operator_stat(op, "/testpath");
* assert(s.error == NULL);
*
* opendal_metadata *meta = s.meta;
* assert(opendal_metadata_last_modified_ms(meta) != -1);
* ```
*/
int64_t opendal_metadata_last_modified_ms(const struct opendal_metadata *self);
/**
* \brief Free the heap-allocated operator pointed by opendal_operator.
*
* Please only use this for a pointer pointing at a valid opendal_operator.
* Calling this function on NULL does nothing, but calling this function on pointers
* of other type will lead to segfault.
*
* # Example
*
* ```C
* opendal_operator *op = opendal_operator_new("fs", NULL);
* // ... use this op, maybe some reads and writes
*
* // free this operator
* opendal_operator_free(op);
* ```
*/
void opendal_operator_free(const struct opendal_operator *ptr);
/**
* \brief Construct an operator based on `scheme` and `options`
*
* Uses an array of key-value pairs to initialize the operator based on provided `scheme`
* and `options`. For each scheme, i.e. Backend, different options could be set, you may
* reference the [documentation](https://opendal.apache.org/docs/category/services/) for
* each service, especially for the **Configuration Part**.
*
* @param scheme the service scheme you want to specify, e.g. "fs", "s3"
* @param options the pointer to the options for this operator, it could be NULL, which means no
* option is set
* @see opendal_operator_options
* @return A valid opendal_result_operator_new setup with the `scheme` and `options` is the construction
* succeeds. On success the operator field is a valid pointer to a newly allocated opendal_operator,
* and the error field is NULL. Otherwise, the operator field is a NULL pointer and the error field.
*
* # Example
*
* Following is an example.
* ```C
* // Allocate a new options
* opendal_operator_options *options = opendal_operator_options_new();
* // Set the options you need
* opendal_operator_options_set(options, "root", "/myroot");
*
* // Construct the operator based on the options and scheme
* opendal_result_operator_new result = opendal_operator_new("memory", options);
* opendal_operator* op = result.op;
*
* // you could free the options right away since the options is not used afterwards
* opendal_operator_options_free(options);
*
* // ... your operations
* ```
*
* # Safety
*
* The only unsafe case is passing an invalid c string pointer to the `scheme` argument.
*/
struct opendal_result_operator_new opendal_operator_new(const char *scheme,
const struct opendal_operator_options *options);
/**
* \brief Blocking write raw bytes to `path`.
*
* Write the `bytes` into the `path` blocking by `op_ptr`.
* Error is NULL if successful, otherwise it contains the error code and error message.
*
* \note It is important to notice that the `bytes` that is passes in will be consumed by this
* function. Therefore, you should not use the `bytes` after this function returns.
*
* @param op The opendal_operator created previously
* @param path The designated path you want to write your bytes in
* @param bytes The opendal_byte typed bytes to be written
* @see opendal_operator
* @see opendal_bytes
* @see opendal_error
* @return NULL if succeeds, otherwise it contains the error code and error message.
*
* # Example
*
* Following is an example
* ```C
* //...prepare your opendal_operator, named op for example
*
* // prepare your data
* char* data = "Hello, World!";
* opendal_bytes bytes = opendal_bytes { .data = (uint8_t*)data, .len = 13 };
*
* // now you can write!
* opendal_error *err = opendal_operator_write(op, "/testpath", bytes);
*
* // Assert that this succeeds
* assert(err == NULL);
* ```
*
* # Safety
*
* It is **safe** under the cases below
* * The memory pointed to by `path` must contain a valid nul terminator at the end of
* the string.
* * The `bytes` provided has valid byte in the `data` field and the `len` field is set
* correctly.
*
* # Panic
*
* * If the `path` points to NULL, this function panics, i.e. exits with information
*/
struct opendal_error *opendal_operator_write(const struct opendal_operator *op,
const char *path,
const struct opendal_bytes *bytes);
/**
* \brief Blocking read the data from `path`.
*
* Read the data out from `path` blocking by operator.
*
* @param op The opendal_operator created previously
* @param path The path you want to read the data out
* @see opendal_operator
* @see opendal_result_read
* @see opendal_error
* @return Returns opendal_result_read, the `data` field is a pointer to a newly allocated
* opendal_bytes, the `error` field contains the error. If the `error` is not NULL, then
* the operation failed and the `data` field is a nullptr.
*
* \note If the read operation succeeds, the returned opendal_bytes is newly allocated on heap.
* After your usage of that, please call opendal_bytes_free() to free the space.
*
* # Example
*
* Following is an example
* ```C
* // ... you have write "Hello, World!" to path "/testpath"
*
* opendal_result_read r = opendal_operator_read(op, "testpath");
* assert(r.error == NULL);
*
* opendal_bytes bytes = r.data;
* assert(bytes.len == 13);
* opendal_bytes_free(&bytes);
* ```
*
* # Safety
*
* It is **safe** under the cases below
* * The memory pointed to by `path` must contain a valid nul terminator at the end of
* the string.
*
* # Panic
*
* * If the `path` points to NULL, this function panics, i.e. exits with information
*/
struct opendal_result_read opendal_operator_read(const struct opendal_operator *op,
const char *path);
/**
* \brief Blocking read the data from `path`.
*
* Read the data out from `path` blocking by operator, returns
* an opendal_result_read with error code.
*
* @param op The opendal_operator created previously
* @param path The path you want to read the data out
* @see opendal_operator
* @see opendal_result_read
* @see opendal_code
* @return Returns opendal_code
*
* \note If the read operation succeeds, the returned opendal_bytes is newly allocated on heap.
* After your usage of that, please call opendal_bytes_free() to free the space.
*
* # Example
*
* Following is an example
* ```C
* // ... you have created an operator named op
*
* opendal_result_operator_reader result = opendal_operator_reader(op, "/testpath");
* assert(result.error == NULL);
* // The reader is in result.reader
* opendal_reader *reader = result.reader;
* ```
*
* # Safety
*
* It is **safe** under the cases below
* * The memory pointed to by `path` must contain a valid nul terminator at the end of
* the string.
*
* # Panic
*
* * If the `path` points to NULL, this function panics, i.e. exits with information
*/
struct opendal_result_operator_reader opendal_operator_reader(const struct opendal_operator *op,
const char *path);
/**
* \brief Blocking create a writer for the specified path.
*
* This function prepares a writer that can be used to write data to the specified path
* using the provided operator. If successful, it returns a valid writer; otherwise, it
* returns an error.
*
* @param op The opendal_operator created previously
* @param path The designated path where the writer will be used
* @see opendal_operator
* @see opendal_result_operator_writer
* @see opendal_error
* @return Returns opendal_result_operator_writer, containing a writer and an opendal_error.
* If the operation succeeds, the `writer` field holds a valid writer and the `error` field