opendal 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (566) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +89 -56
  3. data/Cargo.toml +1 -1
  4. data/DEPENDENCIES.rust.tsv +55 -41
  5. data/LICENSE +201 -0
  6. data/LICENSE-MPL-2.0.txt +373 -0
  7. data/NOTICE +5 -0
  8. data/core/CHANGELOG.md +175 -0
  9. data/core/Cargo.lock +225 -298
  10. data/core/Cargo.toml +100 -94
  11. data/core/DEPENDENCIES.rust.tsv +44 -73
  12. data/core/benches/metadata/README.md +21 -0
  13. data/core/benches/metadata/main.rs +541 -0
  14. data/core/benches/vs_fs/Cargo.toml +1 -1
  15. data/core/benches/vs_s3/Cargo.toml +1 -1
  16. data/core/core/Cargo.toml +7 -2
  17. data/core/core/src/blocking/delete.rs +5 -1
  18. data/core/core/src/blocking/operator.rs +12 -0
  19. data/core/core/src/blocking/read/std_reader.rs +25 -0
  20. data/core/core/src/docs/concepts.rs +70 -94
  21. data/core/core/src/docs/internals/accessor.rs +62 -293
  22. data/core/core/src/docs/internals/layer.rs +43 -59
  23. data/core/core/src/docs/internals/mod.rs +21 -23
  24. data/core/core/src/docs/mod.rs +10 -6
  25. data/core/core/src/docs/performance/concurrent_write.md +92 -55
  26. data/core/core/src/docs/performance/http_optimization.md +120 -104
  27. data/core/core/src/docs/performance/mod.rs +8 -6
  28. data/core/core/src/docs/rfcs/5485_conditional_reader.md +4 -0
  29. data/core/core/src/docs/rfcs/7182_restore_api.md +139 -557
  30. data/core/core/src/docs/rfcs/7945_limited_read.md +210 -0
  31. data/core/core/src/docs/rfcs/7948_s3_provider_presets.md +254 -0
  32. data/core/core/src/docs/rfcs/8109_writer_copy_from.md +330 -0
  33. data/core/core/src/docs/rfcs/8145_conflict_error_kind.md +210 -0
  34. data/core/core/src/docs/rfcs/8147_write_if_not_changed.md +233 -0
  35. data/core/core/src/docs/rfcs/8188_compose_api.md +292 -0
  36. data/core/core/src/docs/rfcs/8194_compact_metadata_and_operation_args.md +444 -0
  37. data/core/core/src/docs/rfcs/README.md +14 -3
  38. data/core/core/src/docs/rfcs/mod.rs +46 -22
  39. data/core/core/src/docs/specs/README.md +34 -0
  40. data/core/core/src/docs/specs/conditional-operations.md +156 -0
  41. data/core/core/src/docs/specs/metadata.md +63 -0
  42. data/core/core/src/docs/specs/mod.rs +26 -0
  43. data/core/core/src/docs/upgrade.md +114 -1
  44. data/core/core/src/layers/capability_override.rs +15 -2
  45. data/core/core/src/layers/complete.rs +347 -43
  46. data/core/core/src/layers/correctness_check.rs +718 -51
  47. data/core/core/src/layers/error_context.rs +76 -2
  48. data/core/core/src/layers/simulate.rs +91 -28
  49. data/core/core/src/lib.rs +1 -0
  50. data/core/core/src/raw/accessor.rs +91 -15
  51. data/core/core/src/raw/enum_utils.rs +7 -0
  52. data/core/core/src/raw/http_util/header.rs +22 -17
  53. data/core/core/src/raw/oio/compose/api.rs +92 -0
  54. data/core/core/src/raw/oio/compose/mod.rs +19 -0
  55. data/core/core/src/raw/oio/copy/api.rs +3 -3
  56. data/core/core/src/raw/oio/copy/block_copy.rs +32 -4
  57. data/core/core/src/raw/oio/copy/multipart_copy.rs +36 -7
  58. data/core/core/src/raw/oio/entry.rs +48 -22
  59. data/core/core/src/raw/oio/list/flat_list.rs +1 -1
  60. data/core/core/src/raw/oio/list/hierarchy_list.rs +3 -2
  61. data/core/core/src/raw/oio/mod.rs +3 -0
  62. data/core/core/src/raw/oio/read/position_read.rs +1 -1
  63. data/core/core/src/raw/oio/write/api.rs +40 -0
  64. data/core/core/src/raw/oio/write/append_write.rs +4 -4
  65. data/core/core/src/raw/oio/write/block_write.rs +2 -2
  66. data/core/core/src/raw/oio/write/multipart_write.rs +181 -48
  67. data/core/core/src/raw/oio/write/position_write.rs +1 -1
  68. data/core/core/src/raw/operation.rs +6 -0
  69. data/core/core/src/raw/ops.rs +1191 -456
  70. data/core/core/src/raw/rps.rs +11 -0
  71. data/core/core/src/raw/time.rs +14 -3
  72. data/core/core/src/services/memory/backend.rs +5 -10
  73. data/core/core/src/services/memory/lister.rs +4 -4
  74. data/core/core/src/services/memory/writer.rs +7 -6
  75. data/core/core/src/types/buffer.rs +102 -12
  76. data/core/core/src/types/bytes_range.rs +20 -1
  77. data/core/core/src/types/capability.rs +65 -0
  78. data/core/core/src/types/compact.rs +329 -0
  79. data/core/core/src/types/compose/composer.rs +183 -0
  80. data/core/core/src/types/compose/input.rs +57 -0
  81. data/core/core/src/types/compose/mod.rs +23 -0
  82. data/core/core/src/types/context/read.rs +16 -11
  83. data/core/core/src/types/context/write.rs +150 -2
  84. data/core/core/src/types/copy.rs +5 -3
  85. data/core/core/src/types/delete/deleter.rs +20 -12
  86. data/core/core/src/types/delete/input.rs +22 -64
  87. data/core/core/src/types/delete/mod.rs +0 -1
  88. data/core/core/src/types/entry.rs +8 -14
  89. data/core/core/src/types/error.rs +28 -11
  90. data/core/core/src/types/metadata.rs +709 -322
  91. data/core/core/src/types/mod.rs +9 -1
  92. data/core/core/src/types/operator/operator.rs +278 -29
  93. data/core/core/src/types/operator/operator_futures.rs +466 -105
  94. data/core/core/src/types/options.rs +631 -158
  95. data/core/core/src/types/read/futures_async_reader.rs +663 -50
  96. data/core/core/src/types/read/reader.rs +23 -5
  97. data/core/core/src/types/write/futures_async_writer.rs +27 -0
  98. data/core/core/src/types/write/writer.rs +47 -5
  99. data/core/http-transports/reqwest/Cargo.toml +1 -1
  100. data/core/layers/async-backtrace/Cargo.toml +2 -2
  101. data/core/layers/async-backtrace/src/lib.rs +21 -2
  102. data/core/layers/await-tree/Cargo.toml +2 -2
  103. data/core/layers/await-tree/src/lib.rs +25 -2
  104. data/core/layers/capability-check/Cargo.toml +2 -2
  105. data/core/layers/capability-check/src/lib.rs +98 -10
  106. data/core/layers/chaos/Cargo.toml +2 -2
  107. data/core/layers/chaos/src/lib.rs +18 -3
  108. data/core/layers/concurrent-limit/Cargo.toml +3 -3
  109. data/core/layers/concurrent-limit/src/lib.rs +53 -13
  110. data/core/layers/dtrace/Cargo.toml +2 -2
  111. data/core/layers/dtrace/src/lib.rs +29 -2
  112. data/core/layers/fastmetrics/Cargo.toml +3 -3
  113. data/core/layers/fastrace/Cargo.toml +2 -2
  114. data/core/layers/fastrace/src/lib.rs +28 -2
  115. data/core/layers/foyer/Cargo.toml +2 -2
  116. data/core/layers/foyer/src/full.rs +16 -19
  117. data/core/layers/foyer/src/lib.rs +67 -14
  118. data/core/layers/hotpath/Cargo.toml +2 -2
  119. data/core/layers/hotpath/src/lib.rs +20 -2
  120. data/core/layers/immutable-index/Cargo.toml +2 -2
  121. data/core/layers/immutable-index/src/lib.rs +48 -24
  122. data/core/layers/logging/Cargo.toml +2 -2
  123. data/core/layers/logging/src/lib.rs +46 -2
  124. data/core/layers/metrics/Cargo.toml +3 -3
  125. data/core/layers/mime-guess/Cargo.toml +2 -2
  126. data/core/layers/mime-guess/src/lib.rs +31 -4
  127. data/core/layers/observe-metrics-common/Cargo.toml +2 -2
  128. data/core/layers/observe-metrics-common/src/lib.rs +55 -2
  129. data/core/layers/otelmetrics/Cargo.toml +3 -3
  130. data/core/layers/oteltrace/Cargo.toml +2 -2
  131. data/core/layers/oteltrace/src/lib.rs +27 -2
  132. data/core/layers/prometheus/Cargo.toml +3 -3
  133. data/core/layers/prometheus-client/Cargo.toml +3 -3
  134. data/core/layers/retry/Cargo.toml +4 -4
  135. data/core/layers/retry/src/lib.rs +76 -19
  136. data/core/layers/route/Cargo.toml +3 -3
  137. data/core/layers/route/src/lib.rs +34 -7
  138. data/core/layers/tail-cut/Cargo.toml +2 -2
  139. data/core/layers/tail-cut/src/lib.rs +28 -2
  140. data/core/layers/throttle/Cargo.toml +2 -2
  141. data/core/layers/throttle/src/lib.rs +19 -2
  142. data/core/layers/timeout/Cargo.toml +3 -3
  143. data/core/layers/timeout/src/lib.rs +38 -13
  144. data/core/layers/tracing/Cargo.toml +2 -2
  145. data/core/layers/tracing/src/lib.rs +24 -3
  146. data/core/services/aliyun-drive/Cargo.toml +2 -2
  147. data/core/services/aliyun-drive/src/backend.rs +34 -24
  148. data/core/services/aliyun-drive/src/core.rs +143 -54
  149. data/core/services/aliyun-drive/src/lister.rs +19 -18
  150. data/core/services/aliyun-drive/src/reader.rs +4 -1
  151. data/core/services/aliyun-drive/src/writer.rs +3 -3
  152. data/core/services/alluxio/Cargo.toml +1 -1
  153. data/core/services/alluxio/src/backend.rs +1 -1
  154. data/core/services/alluxio/src/core.rs +113 -94
  155. data/core/services/alluxio/src/reader.rs +7 -3
  156. data/core/services/alluxio/src/writer.rs +2 -2
  157. data/core/services/azblob/Cargo.toml +2 -2
  158. data/core/services/azblob/src/backend.rs +17 -9
  159. data/core/services/azblob/src/copier.rs +41 -15
  160. data/core/services/azblob/src/core.rs +372 -135
  161. data/core/services/azblob/src/deleter.rs +41 -18
  162. data/core/services/azblob/src/lister.rs +16 -10
  163. data/core/services/azblob/src/reader.rs +4 -1
  164. data/core/services/azblob/src/writer.rs +48 -15
  165. data/core/services/azdls/Cargo.toml +3 -3
  166. data/core/services/azdls/src/backend.rs +45 -15
  167. data/core/services/azdls/src/config.rs +4 -1
  168. data/core/services/azdls/src/core.rs +276 -87
  169. data/core/services/azdls/src/deleter.rs +13 -4
  170. data/core/services/azdls/src/lister.rs +18 -12
  171. data/core/services/azdls/src/reader.rs +6 -2
  172. data/core/services/azdls/src/writer.rs +44 -23
  173. data/core/services/azfile/Cargo.toml +2 -2
  174. data/core/services/azfile/src/backend.rs +24 -8
  175. data/core/services/azfile/src/core.rs +195 -77
  176. data/core/services/azfile/src/deleter.rs +8 -1
  177. data/core/services/azfile/src/lister.rs +20 -14
  178. data/core/services/azfile/src/reader.rs +5 -2
  179. data/core/services/azfile/src/writer.rs +27 -15
  180. data/core/services/azure-common/Cargo.toml +1 -1
  181. data/core/services/b2/Cargo.toml +2 -2
  182. data/core/services/b2/src/backend.rs +30 -11
  183. data/core/services/b2/src/core.rs +134 -120
  184. data/core/services/b2/src/deleter.rs +1 -1
  185. data/core/services/b2/src/lister.rs +5 -2
  186. data/core/services/b2/src/reader.rs +5 -2
  187. data/core/services/b2/src/writer.rs +29 -12
  188. data/core/services/cacache/Cargo.toml +1 -1
  189. data/core/services/cacache/src/backend.rs +4 -5
  190. data/core/services/cacache/src/reader.rs +4 -1
  191. data/core/services/cacache/src/writer.rs +6 -2
  192. data/core/services/cloudflare-kv/Cargo.toml +1 -1
  193. data/core/services/cloudflare-kv/src/backend.rs +26 -15
  194. data/core/services/cloudflare-kv/src/config.rs +13 -2
  195. data/core/services/cloudflare-kv/src/core.rs +62 -56
  196. data/core/services/cloudflare-kv/src/deleter.rs +12 -3
  197. data/core/services/cloudflare-kv/src/lister.rs +66 -17
  198. data/core/services/cloudflare-kv/src/reader.rs +14 -9
  199. data/core/services/cloudflare-kv/src/writer.rs +10 -7
  200. data/core/services/compfs/Cargo.toml +1 -1
  201. data/core/services/compfs/src/backend.rs +11 -7
  202. data/core/services/compfs/src/lister.rs +7 -7
  203. data/core/services/compfs/src/writer.rs +1 -1
  204. data/core/services/cos/Cargo.toml +1 -1
  205. data/core/services/cos/src/backend.rs +129 -16
  206. data/core/services/cos/src/core.rs +198 -80
  207. data/core/services/cos/src/deleter.rs +4 -1
  208. data/core/services/cos/src/lister.rs +42 -27
  209. data/core/services/cos/src/reader.rs +6 -2
  210. data/core/services/cos/src/writer.rs +45 -21
  211. data/core/services/d1/Cargo.toml +1 -1
  212. data/core/services/d1/src/backend.rs +6 -5
  213. data/core/services/d1/src/core.rs +79 -63
  214. data/core/services/d1/src/reader.rs +4 -1
  215. data/core/services/d1/src/writer.rs +6 -2
  216. data/core/services/dashmap/Cargo.toml +1 -1
  217. data/core/services/dashmap/src/backend.rs +2 -2
  218. data/core/services/dashmap/src/reader.rs +4 -1
  219. data/core/services/dashmap/src/writer.rs +11 -8
  220. data/core/services/dbfs/Cargo.toml +1 -1
  221. data/core/services/dbfs/src/backend.rs +21 -15
  222. data/core/services/dbfs/src/core.rs +65 -60
  223. data/core/services/dbfs/src/deleter.rs +4 -1
  224. data/core/services/dbfs/src/lister.rs +10 -10
  225. data/core/services/dbfs/src/writer.rs +6 -3
  226. data/core/services/dropbox/Cargo.toml +2 -2
  227. data/core/services/dropbox/src/backend.rs +30 -23
  228. data/core/services/dropbox/src/core.rs +65 -63
  229. data/core/services/dropbox/src/deleter.rs +1 -1
  230. data/core/services/dropbox/src/lister.rs +17 -8
  231. data/core/services/dropbox/src/reader.rs +4 -1
  232. data/core/services/dropbox/src/writer.rs +13 -10
  233. data/core/services/etcd/Cargo.toml +1 -1
  234. data/core/services/etcd/src/backend.rs +8 -5
  235. data/core/services/etcd/src/core.rs +5 -11
  236. data/core/services/etcd/src/lister.rs +6 -1
  237. data/core/services/etcd/src/reader.rs +4 -1
  238. data/core/services/etcd/src/writer.rs +6 -3
  239. data/core/services/foundationdb/Cargo.toml +1 -1
  240. data/core/services/foundationdb/src/backend.rs +6 -5
  241. data/core/services/foundationdb/src/reader.rs +4 -1
  242. data/core/services/foundationdb/src/writer.rs +6 -2
  243. data/core/services/foyer/Cargo.toml +3 -3
  244. data/core/services/foyer/src/backend.rs +6 -5
  245. data/core/services/foyer/src/reader.rs +4 -1
  246. data/core/services/foyer/src/writer.rs +6 -2
  247. data/core/services/fs/Cargo.toml +1 -1
  248. data/core/services/fs/src/backend.rs +4 -3
  249. data/core/services/fs/src/core.rs +44 -26
  250. data/core/services/fs/src/lister.rs +9 -6
  251. data/core/services/fs/src/writer.rs +20 -13
  252. data/core/services/ftp/Cargo.toml +4 -6
  253. data/core/services/ftp/src/backend.rs +9 -5
  254. data/core/services/ftp/src/core.rs +9 -7
  255. data/core/services/ftp/src/lister.rs +7 -8
  256. data/core/services/ftp/src/reader.rs +3 -3
  257. data/core/services/ftp/src/writer.rs +3 -3
  258. data/core/services/gcs/Cargo.toml +4 -2
  259. data/core/services/gcs/src/backend.rs +53 -7
  260. data/core/services/gcs/src/composer.rs +705 -0
  261. data/core/services/gcs/src/copier.rs +14 -4
  262. data/core/services/gcs/src/core.rs +828 -124
  263. data/core/services/gcs/src/deleter.rs +33 -18
  264. data/core/services/gcs/src/lib.rs +1 -0
  265. data/core/services/gcs/src/lister.rs +21 -12
  266. data/core/services/gcs/src/reader.rs +12 -5
  267. data/core/services/gcs/src/writer.rs +632 -10
  268. data/core/services/gcs-grpc/Cargo.toml +58 -0
  269. data/core/services/gcs-grpc/README.md +19 -0
  270. data/core/services/gcs-grpc/proto/README.md +23 -0
  271. data/core/services/gcs-grpc/proto/google/storage/v2/storage.proto +171 -0
  272. data/core/services/gcs-grpc/proto/upstream-descriptor.bin +0 -0
  273. data/core/services/gcs-grpc/src/backend.rs +449 -0
  274. data/core/services/gcs-grpc/src/config.rs +116 -0
  275. data/core/services/gcs-grpc/src/copier.rs +98 -0
  276. data/core/services/gcs-grpc/src/core.rs +298 -0
  277. data/core/services/gcs-grpc/src/deleter.rs +65 -0
  278. data/core/services/gcs-grpc/src/docs.md +19 -0
  279. data/core/services/gcs-grpc/src/generated/google.storage.v2.rs +541 -0
  280. data/core/services/gcs-grpc/src/generated/mod.rs +24 -0
  281. data/core/services/gcs-grpc/src/lib.rs +43 -0
  282. data/core/services/gcs-grpc/src/lister.rs +125 -0
  283. data/core/services/gcs-grpc/src/reader.rs +140 -0
  284. data/core/services/gcs-grpc/src/writer.rs +780 -0
  285. data/core/services/gdrive/Cargo.toml +2 -2
  286. data/core/services/gdrive/src/backend.rs +123 -69
  287. data/core/services/gdrive/src/core.rs +87 -69
  288. data/core/services/gdrive/src/deleter.rs +8 -2
  289. data/core/services/gdrive/src/lister.rs +38 -26
  290. data/core/services/gdrive/src/path_index.rs +2 -2
  291. data/core/services/gdrive/src/reader.rs +9 -3
  292. data/core/services/gdrive/src/writer.rs +13 -7
  293. data/core/services/ghac/Cargo.toml +2 -2
  294. data/core/services/ghac/src/backend.rs +5 -2
  295. data/core/services/ghac/src/core.rs +59 -37
  296. data/core/services/ghac/src/reader.rs +5 -2
  297. data/core/services/ghac/src/writer.rs +16 -6
  298. data/core/services/github/Cargo.toml +1 -1
  299. data/core/services/github/src/backend.rs +16 -8
  300. data/core/services/github/src/core.rs +88 -76
  301. data/core/services/github/src/lister.rs +17 -15
  302. data/core/services/github/src/reader.rs +5 -2
  303. data/core/services/github/src/writer.rs +12 -6
  304. data/core/services/goosefs/Cargo.toml +2 -2
  305. data/core/services/goosefs/src/backend.rs +2 -2
  306. data/core/services/goosefs/src/core.rs +291 -208
  307. data/core/services/goosefs/src/docs.md +3 -0
  308. data/core/services/goosefs/src/lister.rs +2 -3
  309. data/core/services/goosefs/src/reader.rs +7 -3
  310. data/core/services/goosefs/src/writer.rs +21 -10
  311. data/core/services/goosefs/tests/safe_conditional_put.rs +37 -0
  312. data/core/services/gridfs/Cargo.toml +2 -2
  313. data/core/services/gridfs/src/backend.rs +12 -8
  314. data/core/services/gridfs/src/core.rs +1 -1
  315. data/core/services/gridfs/src/reader.rs +4 -1
  316. data/core/services/gridfs/src/writer.rs +6 -2
  317. data/core/services/hdfs/Cargo.toml +1 -1
  318. data/core/services/hdfs/src/backend.rs +1 -1
  319. data/core/services/hdfs/src/core.rs +7 -4
  320. data/core/services/hdfs/src/lister.rs +7 -9
  321. data/core/services/hdfs/src/writer.rs +5 -1
  322. data/core/services/hdfs-native/Cargo.toml +1 -1
  323. data/core/services/hdfs-native/src/backend.rs +1 -1
  324. data/core/services/hdfs-native/src/core.rs +44 -50
  325. data/core/services/hdfs-native/src/lister.rs +8 -10
  326. data/core/services/hdfs-native/src/writer.rs +5 -1
  327. data/core/services/hf/Cargo.toml +4 -3
  328. data/core/services/hf/src/backend.rs +4 -3
  329. data/core/services/hf/src/core.rs +907 -153
  330. data/core/services/hf/src/lister.rs +16 -6
  331. data/core/services/hf/src/reader.rs +377 -57
  332. data/core/services/hf/src/writer.rs +6 -2
  333. data/core/services/http/Cargo.toml +3 -3
  334. data/core/services/http/src/backend.rs +8 -6
  335. data/core/services/http/src/core.rs +57 -35
  336. data/core/services/http/src/reader.rs +5 -2
  337. data/core/services/ipfs/Cargo.toml +1 -1
  338. data/core/services/ipfs/src/backend.rs +20 -9
  339. data/core/services/ipfs/src/core.rs +43 -34
  340. data/core/services/ipfs/src/reader.rs +5 -2
  341. data/core/services/ipmfs/Cargo.toml +1 -1
  342. data/core/services/ipmfs/src/backend.rs +17 -8
  343. data/core/services/ipmfs/src/core.rs +66 -60
  344. data/core/services/ipmfs/src/deleter.rs +5 -2
  345. data/core/services/ipmfs/src/lister.rs +15 -12
  346. data/core/services/ipmfs/src/reader.rs +5 -2
  347. data/core/services/ipmfs/src/writer.rs +6 -3
  348. data/core/services/koofr/Cargo.toml +2 -2
  349. data/core/services/koofr/src/backend.rs +46 -17
  350. data/core/services/koofr/src/core.rs +64 -48
  351. data/core/services/koofr/src/deleter.rs +4 -1
  352. data/core/services/koofr/src/lister.rs +11 -10
  353. data/core/services/koofr/src/reader.rs +5 -2
  354. data/core/services/koofr/src/writer.rs +13 -7
  355. data/core/services/lakefs/Cargo.toml +1 -1
  356. data/core/services/lakefs/src/backend.rs +25 -8
  357. data/core/services/lakefs/src/core.rs +79 -73
  358. data/core/services/lakefs/src/deleter.rs +4 -1
  359. data/core/services/lakefs/src/lister.rs +17 -14
  360. data/core/services/lakefs/src/reader.rs +5 -2
  361. data/core/services/lakefs/src/writer.rs +11 -10
  362. data/core/services/memcached/Cargo.toml +1 -1
  363. data/core/services/memcached/src/backend.rs +57 -7
  364. data/core/services/memcached/src/config.rs +13 -2
  365. data/core/services/memcached/src/core.rs +11 -1
  366. data/core/services/memcached/src/reader.rs +4 -1
  367. data/core/services/memcached/src/writer.rs +6 -2
  368. data/core/services/mini_moka/Cargo.toml +1 -1
  369. data/core/services/mini_moka/src/backend.rs +8 -8
  370. data/core/services/mini_moka/src/reader.rs +4 -1
  371. data/core/services/mini_moka/src/writer.rs +11 -7
  372. data/core/services/moka/Cargo.toml +1 -1
  373. data/core/services/moka/src/backend.rs +7 -7
  374. data/core/services/moka/src/reader.rs +4 -1
  375. data/core/services/moka/src/writer.rs +10 -6
  376. data/core/services/mongodb/Cargo.toml +2 -2
  377. data/core/services/mongodb/src/backend.rs +7 -6
  378. data/core/services/mongodb/src/core.rs +1 -1
  379. data/core/services/mongodb/src/reader.rs +4 -1
  380. data/core/services/mongodb/src/writer.rs +6 -2
  381. data/core/services/monoiofs/Cargo.toml +2 -2
  382. data/core/services/monoiofs/src/backend.rs +16 -10
  383. data/core/services/monoiofs/src/core.rs +8 -9
  384. data/core/services/monoiofs/src/reader.rs +8 -10
  385. data/core/services/monoiofs/src/writer.rs +19 -24
  386. data/core/services/mysql/Cargo.toml +2 -2
  387. data/core/services/mysql/src/backend.rs +7 -6
  388. data/core/services/mysql/src/core.rs +1 -1
  389. data/core/services/mysql/src/lister.rs +7 -3
  390. data/core/services/mysql/src/reader.rs +4 -1
  391. data/core/services/mysql/src/writer.rs +6 -2
  392. data/core/services/obs/Cargo.toml +1 -1
  393. data/core/services/obs/src/backend.rs +29 -11
  394. data/core/services/obs/src/core.rs +81 -82
  395. data/core/services/obs/src/deleter.rs +4 -1
  396. data/core/services/obs/src/lister.rs +12 -5
  397. data/core/services/obs/src/reader.rs +5 -2
  398. data/core/services/obs/src/writer.rs +40 -19
  399. data/core/services/onedrive/Cargo.toml +2 -2
  400. data/core/services/onedrive/src/backend.rs +30 -21
  401. data/core/services/onedrive/src/config.rs +2 -2
  402. data/core/services/onedrive/src/core.rs +191 -90
  403. data/core/services/onedrive/src/deleter.rs +5 -2
  404. data/core/services/onedrive/src/graph_model.rs +10 -51
  405. data/core/services/onedrive/src/lister.rs +60 -24
  406. data/core/services/onedrive/src/reader.rs +17 -2
  407. data/core/services/onedrive/src/writer.rs +26 -15
  408. data/core/services/opfs/Cargo.toml +1 -1
  409. data/core/services/opfs/src/backend.rs +6 -13
  410. data/core/services/opfs/src/core.rs +33 -37
  411. data/core/services/opfs/src/lister.rs +4 -4
  412. data/core/services/opfs/src/writer.rs +1 -3
  413. data/core/services/oss/Cargo.toml +1 -1
  414. data/core/services/oss/src/backend.rs +40 -8
  415. data/core/services/oss/src/core.rs +192 -92
  416. data/core/services/oss/src/deleter.rs +16 -6
  417. data/core/services/oss/src/lister.rs +43 -27
  418. data/core/services/oss/src/reader.rs +6 -2
  419. data/core/services/oss/src/writer.rs +40 -22
  420. data/core/services/pcloud/Cargo.toml +1 -1
  421. data/core/services/pcloud/src/backend.rs +40 -6
  422. data/core/services/pcloud/src/core.rs +80 -66
  423. data/core/services/pcloud/src/deleter.rs +8 -1
  424. data/core/services/pcloud/src/lister.rs +4 -1
  425. data/core/services/pcloud/src/reader.rs +5 -2
  426. data/core/services/pcloud/src/writer.rs +6 -3
  427. data/core/services/persy/Cargo.toml +1 -1
  428. data/core/services/persy/src/backend.rs +6 -5
  429. data/core/services/persy/src/core.rs +60 -15
  430. data/core/services/persy/src/reader.rs +4 -1
  431. data/core/services/persy/src/writer.rs +6 -2
  432. data/core/services/postgresql/Cargo.toml +2 -2
  433. data/core/services/postgresql/src/backend.rs +7 -6
  434. data/core/services/postgresql/src/core.rs +1 -1
  435. data/core/services/postgresql/src/reader.rs +4 -1
  436. data/core/services/postgresql/src/writer.rs +6 -2
  437. data/core/services/redb/Cargo.toml +1 -1
  438. data/core/services/redb/src/backend.rs +6 -5
  439. data/core/services/redb/src/reader.rs +4 -1
  440. data/core/services/redb/src/writer.rs +6 -2
  441. data/core/services/redis/Cargo.toml +1 -1
  442. data/core/services/redis/src/backend.rs +18 -8
  443. data/core/services/redis/src/config.rs +13 -2
  444. data/core/services/redis/src/reader.rs +8 -4
  445. data/core/services/redis/src/writer.rs +6 -2
  446. data/core/services/rocksdb/Cargo.toml +1 -1
  447. data/core/services/rocksdb/src/backend.rs +6 -5
  448. data/core/services/rocksdb/src/lister.rs +6 -5
  449. data/core/services/rocksdb/src/reader.rs +4 -1
  450. data/core/services/rocksdb/src/writer.rs +6 -2
  451. data/core/services/s3/Cargo.toml +5 -4
  452. data/core/services/s3/src/backend.rs +995 -39
  453. data/core/services/s3/src/compatible_services.md +57 -0
  454. data/core/services/s3/src/config.rs +16 -0
  455. data/core/services/s3/src/copier.rs +190 -55
  456. data/core/services/s3/src/core.rs +299 -190
  457. data/core/services/s3/src/deleter.rs +26 -7
  458. data/core/services/s3/src/docs.md +57 -0
  459. data/core/services/s3/src/lister.rs +55 -36
  460. data/core/services/s3/src/reader.rs +22 -2
  461. data/core/services/s3/src/writer.rs +154 -32
  462. data/core/services/seafile/Cargo.toml +2 -2
  463. data/core/services/seafile/src/backend.rs +3 -3
  464. data/core/services/seafile/src/core.rs +105 -79
  465. data/core/services/seafile/src/lister.rs +11 -8
  466. data/core/services/seafile/src/reader.rs +5 -2
  467. data/core/services/seafile/src/writer.rs +6 -3
  468. data/core/services/sftp/Cargo.toml +1 -1
  469. data/core/services/sftp/src/backend.rs +19 -4
  470. data/core/services/sftp/src/core.rs +51 -46
  471. data/core/services/sftp/src/lister.rs +4 -4
  472. data/core/services/sftp/src/writer.rs +1 -1
  473. data/core/services/sled/Cargo.toml +1 -1
  474. data/core/services/sled/src/backend.rs +6 -5
  475. data/core/services/sled/src/core.rs +28 -6
  476. data/core/services/sled/src/lister.rs +6 -5
  477. data/core/services/sled/src/reader.rs +4 -1
  478. data/core/services/sled/src/writer.rs +6 -2
  479. data/core/services/sqlite/Cargo.toml +2 -2
  480. data/core/services/sqlite/src/backend.rs +12 -7
  481. data/core/services/sqlite/src/core.rs +3 -3
  482. data/core/services/sqlite/src/reader.rs +4 -1
  483. data/core/services/sqlite/src/writer.rs +7 -3
  484. data/core/services/surrealdb/Cargo.toml +2 -2
  485. data/core/services/surrealdb/src/backend.rs +7 -6
  486. data/core/services/surrealdb/src/core.rs +1 -1
  487. data/core/services/surrealdb/src/reader.rs +4 -1
  488. data/core/services/surrealdb/src/writer.rs +6 -2
  489. data/core/services/swift/Cargo.toml +1 -1
  490. data/core/services/swift/src/backend.rs +38 -8
  491. data/core/services/swift/src/core.rs +63 -67
  492. data/core/services/swift/src/deleter.rs +8 -2
  493. data/core/services/swift/src/lister.rs +11 -8
  494. data/core/services/swift/src/reader.rs +5 -2
  495. data/core/services/swift/src/writer.rs +17 -8
  496. data/core/services/tikv/Cargo.toml +2 -2
  497. data/core/services/tikv/src/backend.rs +7 -6
  498. data/core/services/tikv/src/core.rs +31 -14
  499. data/core/services/tikv/src/reader.rs +4 -1
  500. data/core/services/tikv/src/writer.rs +6 -2
  501. data/core/services/tos/Cargo.toml +2 -2
  502. data/core/services/tos/src/backend.rs +45 -21
  503. data/core/services/tos/src/copier.rs +44 -17
  504. data/core/services/tos/src/core.rs +147 -117
  505. data/core/services/tos/src/deleter.rs +9 -3
  506. data/core/services/tos/src/docs.md +1 -1
  507. data/core/services/tos/src/lister.rs +43 -28
  508. data/core/services/tos/src/reader.rs +5 -2
  509. data/core/services/tos/src/writer.rs +37 -16
  510. data/core/services/upyun/Cargo.toml +1 -1
  511. data/core/services/upyun/src/backend.rs +30 -7
  512. data/core/services/upyun/src/core.rs +122 -87
  513. data/core/services/upyun/src/deleter.rs +4 -1
  514. data/core/services/upyun/src/lister.rs +10 -10
  515. data/core/services/upyun/src/reader.rs +5 -2
  516. data/core/services/upyun/src/writer.rs +19 -7
  517. data/core/services/vercel-artifacts/Cargo.toml +1 -1
  518. data/core/services/vercel-artifacts/src/backend.rs +6 -3
  519. data/core/services/vercel-artifacts/src/core.rs +32 -27
  520. data/core/services/vercel-artifacts/src/reader.rs +5 -2
  521. data/core/services/vercel-artifacts/src/writer.rs +6 -3
  522. data/core/services/vercel-blob/Cargo.toml +1 -1
  523. data/core/services/vercel-blob/src/backend.rs +23 -6
  524. data/core/services/vercel-blob/src/core.rs +92 -81
  525. data/core/services/vercel-blob/src/lister.rs +12 -3
  526. data/core/services/vercel-blob/src/reader.rs +5 -2
  527. data/core/services/vercel-blob/src/writer.rs +19 -7
  528. data/core/services/webdav/Cargo.toml +2 -2
  529. data/core/services/webdav/src/backend.rs +25 -5
  530. data/core/services/webdav/src/core.rs +116 -59
  531. data/core/services/webdav/src/deleter.rs +4 -1
  532. data/core/services/webdav/src/lister.rs +4 -1
  533. data/core/services/webdav/src/reader.rs +6 -2
  534. data/core/services/webdav/src/writer.rs +17 -7
  535. data/core/services/webhdfs/Cargo.toml +2 -2
  536. data/core/services/webhdfs/src/backend.rs +24 -11
  537. data/core/services/webhdfs/src/core.rs +99 -98
  538. data/core/services/webhdfs/src/deleter.rs +5 -2
  539. data/core/services/webhdfs/src/lister.rs +21 -9
  540. data/core/services/webhdfs/src/reader.rs +5 -2
  541. data/core/services/webhdfs/src/writer.rs +49 -14
  542. data/core/services/yandex-disk/Cargo.toml +1 -1
  543. data/core/services/yandex-disk/src/backend.rs +28 -6
  544. data/core/services/yandex-disk/src/core.rs +97 -79
  545. data/core/services/yandex-disk/src/deleter.rs +4 -1
  546. data/core/services/yandex-disk/src/lister.rs +25 -9
  547. data/core/services/yandex-disk/src/reader.rs +5 -2
  548. data/core/services/yandex-disk/src/writer.rs +6 -3
  549. data/core/src/lib.rs +5 -0
  550. data/core/testkit/Cargo.toml +4 -4
  551. data/core/testkit/src/utils.rs +53 -8
  552. data/core/tests/behavior/async_compose.rs +297 -0
  553. data/core/tests/behavior/async_copy.rs +162 -1
  554. data/core/tests/behavior/async_delete.rs +364 -3
  555. data/core/tests/behavior/async_read.rs +86 -0
  556. data/core/tests/behavior/async_restore.rs +162 -0
  557. data/core/tests/behavior/async_stat.rs +90 -0
  558. data/core/tests/behavior/async_write.rs +330 -2
  559. data/core/tests/behavior/main.rs +4 -0
  560. data/core/upgrade.md +114 -1
  561. data/src/capability.rs +0 -1
  562. data/src/io.rs +0 -1
  563. data/src/lister.rs +0 -1
  564. data/src/metadata.rs +0 -1
  565. data/src/operator_info.rs +0 -1
  566. metadata +44 -2
@@ -20,11 +20,43 @@
20
20
  //! By using ops, users can add more context for operation.
21
21
 
22
22
  use crate::BytesRange;
23
+ use crate::UserMetadata;
23
24
  use crate::options;
24
25
  use crate::raw::*;
26
+ use crate::types::compact::CompactValues;
27
+ use crate::types::metadata::user_metadata_encoded_len;
28
+ use crate::types::metadata::write_user_metadata;
29
+ use crate::{Capability, Error, ErrorKind, Result};
25
30
 
26
31
  use std::collections::HashMap;
27
32
 
33
+ #[inline]
34
+ fn string_value(values: &CompactValues, field: usize) -> Option<&str> {
35
+ values.get_str(field)
36
+ }
37
+
38
+ #[inline]
39
+ fn encode_timestamp(value: Timestamp) -> [u8; 12] {
40
+ let value = value.into_inner();
41
+ let mut encoded = [0; 12];
42
+ encoded[..8].copy_from_slice(&value.as_second().to_le_bytes());
43
+ encoded[8..].copy_from_slice(&value.subsec_nanosecond().to_le_bytes());
44
+ encoded
45
+ }
46
+
47
+ #[inline]
48
+ fn decode_timestamp(value: &[u8]) -> Timestamp {
49
+ let seconds = i64::from_le_bytes(value[..8].try_into().unwrap());
50
+ let nanoseconds = i32::from_le_bytes(value[8..].try_into().unwrap());
51
+ Timestamp::new(seconds, nanoseconds).expect("operation stores a previously validated timestamp")
52
+ }
53
+
54
+ fn sorted_user_metadata(value: HashMap<String, String>) -> Vec<(String, String)> {
55
+ let mut value: Vec<_> = value.into_iter().collect();
56
+ value.sort_unstable_by(|left, right| left.0.cmp(&right.0));
57
+ value
58
+ }
59
+
28
60
  /// Arguments for `create` operation.
29
61
  ///
30
62
  /// The path must be normalized.
@@ -43,11 +75,19 @@ impl OpCreateDir {
43
75
  /// The path must be normalized.
44
76
  #[derive(Debug, Clone, Default, Eq, Hash, PartialEq)]
45
77
  pub struct OpDelete {
46
- /// The version of the object to delete.
47
- version: Option<String>,
78
+ flags: u8,
79
+ values: CompactValues,
80
+ }
48
81
 
49
- /// Whether a `delete` is recursive.
50
- recursive: bool,
82
+ const OP_DELETE_RECURSIVE: u8 = 1;
83
+
84
+ #[repr(usize)]
85
+ enum DeleteField {
86
+ Version,
87
+ IfMatch,
88
+ IfNoneMatch,
89
+ IfVersionMatch,
90
+ IfVersionNotMatch,
51
91
  }
52
92
 
53
93
  impl OpDelete {
@@ -55,39 +95,130 @@ impl OpDelete {
55
95
  pub fn new() -> Self {
56
96
  Self::default()
57
97
  }
58
- }
59
98
 
60
- impl OpDelete {
61
- /// Set the version of the object to delete.
62
- pub fn with_version(mut self, version: &str) -> Self {
63
- self.version = Some(version.into());
64
- self
65
- }
99
+ /// Lower `options` against `capability` and freeze them into service-ready arguments.
100
+ ///
101
+ /// # Errors
102
+ ///
103
+ /// Returns an error when `if_not_changed` contains no identity or conflicts
104
+ /// with an explicit equality condition.
105
+ ///
106
+ /// # Panics
107
+ ///
108
+ /// Panics when the compact value block, including its index, exceeds `u16::MAX` bytes.
109
+ pub fn from_options(
110
+ capability: &Capability,
111
+ mut options: options::DeleteOptions,
112
+ ) -> Result<Self> {
113
+ if let Some(metadata) = options.if_not_changed.take() {
114
+ let (target, identity, name) = if capability.delete_with_if_version_match
115
+ && let Some(version) = metadata.version()
116
+ {
117
+ (&mut options.if_version_match, version, "if_version_match")
118
+ } else if let Some(etag) = metadata.etag() {
119
+ (&mut options.if_match, etag, "if_match")
120
+ } else if let Some(version) = metadata.version() {
121
+ (&mut options.if_version_match, version, "if_version_match")
122
+ } else {
123
+ return Err(Error::new(
124
+ ErrorKind::ConfigInvalid,
125
+ "if_not_changed metadata contains neither version nor ETag",
126
+ )
127
+ .with_operation(Operation::Delete));
128
+ };
129
+
130
+ if let Some(explicit) = target {
131
+ if explicit != identity {
132
+ return Err(Error::new(
133
+ ErrorKind::ConditionNotMatch,
134
+ format!("if_not_changed conflicts with {name}"),
135
+ )
136
+ .with_operation(Operation::Delete));
137
+ }
138
+ } else {
139
+ *target = Some(identity.to_owned());
140
+ }
141
+ }
66
142
 
67
- /// Change the recursive flag of this delete operation.
68
- pub fn with_recursive(mut self, recursive: bool) -> Self {
69
- self.recursive = recursive;
70
- self
143
+ let fields = [
144
+ options.version.as_deref().map(str::as_bytes),
145
+ options.if_match.as_deref().map(str::as_bytes),
146
+ options.if_none_match.as_deref().map(str::as_bytes),
147
+ options.if_version_match.as_deref().map(str::as_bytes),
148
+ options.if_version_not_match.as_deref().map(str::as_bytes),
149
+ ];
150
+ Ok(Self {
151
+ flags: if options.recursive {
152
+ OP_DELETE_RECURSIVE
153
+ } else {
154
+ 0
155
+ },
156
+ values: CompactValues::encode(&fields),
157
+ })
71
158
  }
159
+ }
72
160
 
161
+ impl OpDelete {
73
162
  /// Return the version of the object to delete.
163
+ #[inline]
74
164
  pub fn version(&self) -> Option<&str> {
75
- self.version.as_deref()
165
+ string_value(&self.values, DeleteField::Version as usize)
76
166
  }
77
167
 
78
168
  /// Whether this delete should remove objects recursively.
169
+ #[inline]
79
170
  pub fn recursive(&self) -> bool {
80
- self.recursive
171
+ self.flags & OP_DELETE_RECURSIVE != 0
81
172
  }
82
- }
83
173
 
84
- impl From<options::DeleteOptions> for OpDelete {
85
- fn from(value: options::DeleteOptions) -> Self {
86
- Self {
87
- version: value.version,
88
- recursive: value.recursive,
174
+ /// Return the ETag that the object must match before deletion.
175
+ #[inline]
176
+ pub fn if_match(&self) -> Option<&str> {
177
+ string_value(&self.values, DeleteField::IfMatch as usize)
178
+ }
179
+
180
+ /// Return the ETag that the object must not match before deletion.
181
+ #[inline]
182
+ pub fn if_none_match(&self) -> Option<&str> {
183
+ string_value(&self.values, DeleteField::IfNoneMatch as usize)
184
+ }
185
+
186
+ /// Return the version that the current object must match before deletion.
187
+ #[inline]
188
+ pub fn if_version_match(&self) -> Option<&str> {
189
+ string_value(&self.values, DeleteField::IfVersionMatch as usize)
190
+ }
191
+
192
+ /// Return the version that the current object must not match before deletion.
193
+ #[inline]
194
+ pub fn if_version_not_match(&self) -> Option<&str> {
195
+ string_value(&self.values, DeleteField::IfVersionNotMatch as usize)
196
+ }
197
+
198
+ /// Returns whether at least one value-bearing conditional option is set.
199
+ #[inline]
200
+ pub fn is_conditional(&self) -> bool {
201
+ self.if_match().is_some()
202
+ || self.if_none_match().is_some()
203
+ || self.if_version_match().is_some()
204
+ || self.if_version_not_match().is_some()
205
+ }
206
+
207
+ pub(crate) fn set_recursive(&mut self, recursive: bool) {
208
+ if recursive {
209
+ self.flags |= OP_DELETE_RECURSIVE;
210
+ } else {
211
+ self.flags &= !OP_DELETE_RECURSIVE;
89
212
  }
90
213
  }
214
+
215
+ #[doc(hidden)]
216
+ pub fn into_version(mut self, version: &str) -> Self {
217
+ self.values = self
218
+ .values
219
+ .replace(DeleteField::Version as usize, version.as_bytes());
220
+ self
221
+ }
91
222
  }
92
223
 
93
224
  /// Arguments for `delete` operation.
@@ -109,132 +240,79 @@ pub struct OpList {
109
240
  /// The maximum number of results that the service should return per request.
110
241
  ///
111
242
  /// This can be used to control the memory consumption of a list operation.
112
- limit: Option<usize>,
113
-
114
- /// The key after which the service should start listing.
115
- start_after: Option<String>,
116
-
117
- /// Whether the list operation is recursive.
118
- ///
119
- /// - If `false`, the operation lists only the immediate children of the given
120
- /// path.
121
- /// - If `true`, the operation lists all entries whose paths start with the
122
- /// given path.
123
- ///
124
- /// Defaults to `false`.
125
- recursive: bool,
126
-
127
- /// Whether to return object versions.
128
- ///
129
- /// - If `false`, the operation does not return object versions.
130
- /// - If `true`, the operation returns object versions when the service
131
- /// supports versioning.
132
- ///
133
- /// Defaults to `false`.
134
- versions: bool,
135
-
136
- /// Whether to return deleted objects.
137
- ///
138
- /// - If `false`, the operation does not return deleted objects.
139
- /// - If `true`, the operation returns deleted objects when the service
140
- /// supports versioning.
141
- ///
142
- /// Defaults to `false`.
143
- deleted: bool,
243
+ limit: usize,
244
+ flags: u8,
245
+ values: CompactValues,
144
246
  }
145
247
 
248
+ const OP_LIST_HAS_LIMIT: u8 = 1;
249
+ const OP_LIST_RECURSIVE: u8 = 1 << 1;
250
+ const OP_LIST_VERSIONS: u8 = 1 << 2;
251
+ const OP_LIST_DELETED: u8 = 1 << 3;
252
+
146
253
  impl OpList {
147
254
  /// Create a new `OpList`.
148
255
  pub fn new() -> Self {
149
256
  Self::default()
150
257
  }
151
258
 
152
- /// Set the maximum number of results per request.
153
- pub fn with_limit(mut self, limit: usize) -> Self {
154
- self.limit = Some(limit);
155
- self
156
- }
157
-
158
259
  /// Return the maximum number of results per request.
260
+ #[inline]
159
261
  pub fn limit(&self) -> Option<usize> {
160
- self.limit
161
- }
162
-
163
- /// Set the key after which listing should start.
164
- pub fn with_start_after(mut self, start_after: &str) -> Self {
165
- self.start_after = Some(start_after.into());
166
- self
262
+ (self.flags & OP_LIST_HAS_LIMIT != 0).then_some(self.limit)
167
263
  }
168
264
 
169
265
  /// Return the key after which listing should start.
266
+ #[inline]
170
267
  pub fn start_after(&self) -> Option<&str> {
171
- self.start_after.as_deref()
172
- }
173
-
174
- /// Set whether the list operation is recursive.
175
- ///
176
- /// - If `false`, the operation lists only the immediate children of the given
177
- /// path.
178
- /// - If `true`, the operation lists all entries whose paths start with the
179
- /// given path.
180
- ///
181
- /// Defaults to `false`.
182
- pub fn with_recursive(mut self, recursive: bool) -> Self {
183
- self.recursive = recursive;
184
- self
268
+ string_value(&self.values, 0)
185
269
  }
186
270
 
187
271
  /// Return whether the list operation is recursive.
272
+ #[inline]
188
273
  pub fn recursive(&self) -> bool {
189
- self.recursive
190
- }
191
-
192
- /// Change the concurrent of this list operation.
193
- ///
194
- /// The default concurrent is 1.
195
- #[deprecated(since = "0.53.2", note = "concurrent in list is no-op")]
196
- pub fn with_concurrent(self, concurrent: usize) -> Self {
197
- let _ = concurrent;
198
- self
274
+ self.flags & OP_LIST_RECURSIVE != 0
199
275
  }
200
276
 
201
277
  /// Get the concurrent of list operation.
202
278
  #[deprecated(since = "0.53.2", note = "concurrent in list is no-op")]
279
+ #[inline]
203
280
  pub fn concurrent(&self) -> usize {
204
281
  0
205
282
  }
206
283
 
207
- /// Set whether to return object versions.
208
- pub fn with_versions(mut self, versions: bool) -> Self {
209
- self.versions = versions;
210
- self
211
- }
212
-
213
284
  /// Return whether the operation includes object versions.
285
+ #[inline]
214
286
  pub fn versions(&self) -> bool {
215
- self.versions
216
- }
217
-
218
- /// Set whether to return deleted objects.
219
- pub fn with_deleted(mut self, deleted: bool) -> Self {
220
- self.deleted = deleted;
221
- self
287
+ self.flags & OP_LIST_VERSIONS != 0
222
288
  }
223
289
 
224
290
  /// Return whether the operation includes deleted objects.
291
+ #[inline]
225
292
  pub fn deleted(&self) -> bool {
226
- self.deleted
293
+ self.flags & OP_LIST_DELETED != 0
227
294
  }
228
295
  }
229
296
 
230
297
  impl From<options::ListOptions> for OpList {
231
298
  fn from(value: options::ListOptions) -> Self {
299
+ let mut flags = 0;
300
+ if value.limit.is_some() {
301
+ flags |= OP_LIST_HAS_LIMIT;
302
+ }
303
+ if value.recursive {
304
+ flags |= OP_LIST_RECURSIVE;
305
+ }
306
+ if value.versions {
307
+ flags |= OP_LIST_VERSIONS;
308
+ }
309
+ if value.deleted {
310
+ flags |= OP_LIST_DELETED;
311
+ }
232
312
  Self {
233
- limit: value.limit,
234
- start_after: value.start_after,
235
- recursive: value.recursive,
236
- versions: value.versions,
237
- deleted: value.deleted,
313
+ limit: value.limit.unwrap_or_default(),
314
+ flags,
315
+ values: CompactValues::encode(&[value.start_after.as_deref().map(str::as_bytes)]),
238
316
  }
239
317
  }
240
318
  }
@@ -315,15 +393,22 @@ impl From<OpDelete> for PresignOperation {
315
393
  /// Arguments for `read` operation.
316
394
  #[derive(Debug, Clone, Default)]
317
395
  pub struct OpRead {
318
- if_match: Option<String>,
319
- if_none_match: Option<String>,
320
- if_modified_since: Option<Timestamp>,
321
- if_unmodified_since: Option<Timestamp>,
322
- override_content_type: Option<String>,
323
- override_cache_control: Option<String>,
324
- override_content_disposition: Option<String>,
325
- version: Option<String>,
326
- content_length_hint: Option<u64>,
396
+ values: CompactValues,
397
+ }
398
+
399
+ #[repr(usize)]
400
+ enum ReadField {
401
+ IfMatch,
402
+ IfNoneMatch,
403
+ IfVersionMatch,
404
+ IfVersionNotMatch,
405
+ IfModifiedSince,
406
+ IfUnmodifiedSince,
407
+ OverrideContentType,
408
+ OverrideCacheControl,
409
+ OverrideContentDisposition,
410
+ Version,
411
+ ContentLengthHint,
327
412
  }
328
413
 
329
414
  impl OpRead {
@@ -332,97 +417,162 @@ impl OpRead {
332
417
  Self::default()
333
418
  }
334
419
 
335
- /// Sets the content-disposition header that should be sent back by the remote read operation.
336
- pub fn with_override_content_disposition(mut self, content_disposition: &str) -> Self {
337
- self.override_content_disposition = Some(content_disposition.into());
338
- self
420
+ /// Lower compose source `options` against `capability` and freeze them into
421
+ /// service-ready read arguments.
422
+ ///
423
+ /// # Errors
424
+ ///
425
+ /// Returns an error when `if_not_changed` contains no identity or conflicts
426
+ /// with an explicit source equality condition.
427
+ ///
428
+ /// # Panics
429
+ ///
430
+ /// Panics when the compact value block, including its index, exceeds `u16::MAX` bytes.
431
+ pub(crate) fn from_compose_source_options(
432
+ capability: &Capability,
433
+ mut options: options::ComposeSourceOptions,
434
+ ) -> Result<Self> {
435
+ if let Some(metadata) = options.if_not_changed.take() {
436
+ let (target, identity, name) = if capability.compose_with_source_version
437
+ && let Some(version) = metadata.version()
438
+ {
439
+ (&mut options.version, version, "source version")
440
+ } else if let Some(etag) = metadata.etag() {
441
+ (&mut options.if_match, etag, "source if_match")
442
+ } else if let Some(version) = metadata.version() {
443
+ (&mut options.version, version, "source version")
444
+ } else {
445
+ return Err(Error::new(
446
+ ErrorKind::ConfigInvalid,
447
+ "if_not_changed metadata contains neither version nor ETag",
448
+ )
449
+ .with_operation(Operation::Compose));
450
+ };
451
+
452
+ if let Some(explicit) = target {
453
+ if explicit != identity {
454
+ return Err(Error::new(
455
+ ErrorKind::ConditionNotMatch,
456
+ format!("if_not_changed conflicts with {name}"),
457
+ )
458
+ .with_operation(Operation::Compose));
459
+ }
460
+ } else {
461
+ *target = Some(identity.to_owned());
462
+ }
463
+ }
464
+
465
+ Ok(Self::from_read_options(options::ReadOptions {
466
+ version: options.version,
467
+ if_match: options.if_match,
468
+ ..Default::default()
469
+ }))
339
470
  }
340
471
 
341
472
  /// Returns the content-disposition header that should be sent back by the remote read
342
473
  /// operation.
474
+ #[inline]
343
475
  pub fn override_content_disposition(&self) -> Option<&str> {
344
- self.override_content_disposition.as_deref()
345
- }
346
-
347
- /// Sets the cache-control header that should be sent back by the remote read operation.
348
- pub fn with_override_cache_control(mut self, cache_control: &str) -> Self {
349
- self.override_cache_control = Some(cache_control.into());
350
- self
476
+ string_value(&self.values, ReadField::OverrideContentDisposition as usize)
351
477
  }
352
478
 
353
479
  /// Returns the cache-control header that should be sent back by the remote read operation.
480
+ #[inline]
354
481
  pub fn override_cache_control(&self) -> Option<&str> {
355
- self.override_cache_control.as_deref()
356
- }
357
-
358
- /// Sets the content-type header that should be sent back by the remote read operation.
359
- pub fn with_override_content_type(mut self, content_type: &str) -> Self {
360
- self.override_content_type = Some(content_type.into());
361
- self
482
+ string_value(&self.values, ReadField::OverrideCacheControl as usize)
362
483
  }
363
484
 
364
485
  /// Returns the content-type header that should be sent back by the remote read operation.
486
+ #[inline]
365
487
  pub fn override_content_type(&self) -> Option<&str> {
366
- self.override_content_type.as_deref()
367
- }
368
-
369
- /// Set the If-Match of the option
370
- pub fn with_if_match(mut self, if_match: &str) -> Self {
371
- self.if_match = Some(if_match.to_string());
372
- self
488
+ string_value(&self.values, ReadField::OverrideContentType as usize)
373
489
  }
374
490
 
375
491
  /// Get If-Match from option
492
+ #[inline]
376
493
  pub fn if_match(&self) -> Option<&str> {
377
- self.if_match.as_deref()
378
- }
379
-
380
- /// Set the If-None-Match of the option
381
- pub fn with_if_none_match(mut self, if_none_match: &str) -> Self {
382
- self.if_none_match = Some(if_none_match.to_string());
383
- self
494
+ string_value(&self.values, ReadField::IfMatch as usize)
384
495
  }
385
496
 
386
497
  /// Get If-None-Match from option
498
+ #[inline]
387
499
  pub fn if_none_match(&self) -> Option<&str> {
388
- self.if_none_match.as_deref()
500
+ string_value(&self.values, ReadField::IfNoneMatch as usize)
389
501
  }
390
502
 
391
- /// Set the If-Modified-Since of the option
392
- pub fn with_if_modified_since(mut self, v: Timestamp) -> Self {
393
- self.if_modified_since = Some(v);
394
- self
503
+ /// Get the version match condition.
504
+ #[inline]
505
+ pub fn if_version_match(&self) -> Option<&str> {
506
+ string_value(&self.values, ReadField::IfVersionMatch as usize)
395
507
  }
396
508
 
397
- /// Return the If-Modified-Since condition.
398
- pub fn if_modified_since(&self) -> Option<Timestamp> {
399
- self.if_modified_since
509
+ /// Get the version non-match condition.
510
+ #[inline]
511
+ pub fn if_version_not_match(&self) -> Option<&str> {
512
+ string_value(&self.values, ReadField::IfVersionNotMatch as usize)
400
513
  }
401
514
 
402
- /// Set the If-Unmodified-Since of the option
403
- pub fn with_if_unmodified_since(mut self, v: Timestamp) -> Self {
404
- self.if_unmodified_since = Some(v);
405
- self
515
+ /// Return the If-Modified-Since condition.
516
+ #[inline]
517
+ pub fn if_modified_since(&self) -> Option<Timestamp> {
518
+ self.values
519
+ .get(ReadField::IfModifiedSince as usize)
520
+ .map(decode_timestamp)
406
521
  }
407
522
 
408
523
  /// Get If-Unmodified-Since from option
524
+ #[inline]
409
525
  pub fn if_unmodified_since(&self) -> Option<Timestamp> {
410
- self.if_unmodified_since
526
+ self.values
527
+ .get(ReadField::IfUnmodifiedSince as usize)
528
+ .map(decode_timestamp)
411
529
  }
412
530
 
413
- /// Set the version of the option
414
- pub fn with_version(mut self, version: &str) -> Self {
415
- self.version = Some(version.to_string());
416
- self
531
+ /// Returns whether at least one value-bearing conditional option is set.
532
+ #[inline]
533
+ pub fn is_conditional(&self) -> bool {
534
+ self.if_match().is_some()
535
+ || self.if_none_match().is_some()
536
+ || self.if_version_match().is_some()
537
+ || self.if_version_not_match().is_some()
538
+ || self.if_modified_since().is_some()
539
+ || self.if_unmodified_since().is_some()
417
540
  }
418
541
 
419
542
  /// Get version from option
543
+ #[inline]
420
544
  pub fn version(&self) -> Option<&str> {
421
- self.version.as_deref()
545
+ string_value(&self.values, ReadField::Version as usize)
422
546
  }
423
547
 
424
548
  pub(crate) fn content_length_hint(&self) -> Option<u64> {
425
- self.content_length_hint
549
+ self.values
550
+ .get(ReadField::ContentLengthHint as usize)
551
+ .map(|value| u64::from_le_bytes(value.try_into().unwrap()))
552
+ }
553
+
554
+ fn from_read_options(value: options::ReadOptions) -> Self {
555
+ let if_modified_since = value.if_modified_since.map(encode_timestamp);
556
+ let if_unmodified_since = value.if_unmodified_since.map(encode_timestamp);
557
+ let content_length_hint = value.content_length_hint.map(u64::to_le_bytes);
558
+ Self {
559
+ values: CompactValues::encode(&[
560
+ value.if_match.as_deref().map(str::as_bytes),
561
+ value.if_none_match.as_deref().map(str::as_bytes),
562
+ value.if_version_match.as_deref().map(str::as_bytes),
563
+ value.if_version_not_match.as_deref().map(str::as_bytes),
564
+ if_modified_since.as_ref().map(|value| value.as_slice()),
565
+ if_unmodified_since.as_ref().map(|value| value.as_slice()),
566
+ value.override_content_type.as_deref().map(str::as_bytes),
567
+ value.override_cache_control.as_deref().map(str::as_bytes),
568
+ value
569
+ .override_content_disposition
570
+ .as_deref()
571
+ .map(str::as_bytes),
572
+ value.version.as_deref().map(str::as_bytes),
573
+ content_length_hint.as_ref().map(|value| value.as_slice()),
574
+ ]),
575
+ }
426
576
  }
427
577
  }
428
578
 
@@ -479,8 +629,11 @@ impl OpReader {
479
629
  }
480
630
 
481
631
  /// Set the gap size.
632
+ ///
633
+ /// Set to `0` to disable merging ranges separated by a gap. Overlapping or
634
+ /// adjacent ranges are still merged.
482
635
  pub fn with_gap(mut self, gap: usize) -> Self {
483
- self.gap = Some(gap.max(1));
636
+ self.gap = Some(gap);
484
637
  self
485
638
  }
486
639
 
@@ -503,66 +656,44 @@ impl OpReader {
503
656
 
504
657
  impl From<options::ReadOptions> for (BytesRange, OpRead, OpReader) {
505
658
  fn from(value: options::ReadOptions) -> Self {
506
- (
507
- value.range,
508
- OpRead {
509
- if_match: value.if_match,
510
- if_none_match: value.if_none_match,
511
- if_modified_since: value.if_modified_since,
512
- if_unmodified_since: value.if_unmodified_since,
513
- override_content_type: value.override_content_type,
514
- override_cache_control: value.override_cache_control,
515
- override_content_disposition: value.override_content_disposition,
516
- version: value.version,
517
- content_length_hint: value.content_length_hint,
518
- },
519
- OpReader {
520
- // Ensure concurrent is at least 1
521
- concurrent: value.concurrent.max(1),
522
- chunk: value.chunk,
523
- gap: value.gap,
524
- prefetch: 0,
525
- },
526
- )
659
+ let range = value.range;
660
+ let reader = OpReader {
661
+ concurrent: value.concurrent.max(1),
662
+ chunk: value.chunk,
663
+ gap: value.gap,
664
+ prefetch: 0,
665
+ };
666
+ (range, OpRead::from_read_options(value), reader)
527
667
  }
528
668
  }
529
669
 
530
670
  impl From<options::ReaderOptions> for (OpRead, OpReader) {
531
671
  fn from(value: options::ReaderOptions) -> Self {
532
- (
533
- OpRead {
534
- if_match: value.if_match,
535
- if_none_match: value.if_none_match,
536
- if_modified_since: value.if_modified_since,
537
- if_unmodified_since: value.if_unmodified_since,
538
- override_content_type: None,
539
- override_cache_control: None,
540
- override_content_disposition: None,
541
- version: value.version,
542
- content_length_hint: value.content_length_hint,
543
- },
544
- OpReader {
545
- // Ensure concurrent is at least 1
546
- concurrent: value.concurrent.max(1),
547
- chunk: value.chunk,
548
- gap: value.gap,
549
- prefetch: value.prefetch,
550
- },
551
- )
672
+ let reader = OpReader {
673
+ concurrent: value.concurrent.max(1),
674
+ chunk: value.chunk,
675
+ gap: value.gap,
676
+ prefetch: value.prefetch,
677
+ };
678
+ let read = options::ReadOptions {
679
+ version: value.version,
680
+ if_match: value.if_match,
681
+ if_none_match: value.if_none_match,
682
+ if_version_match: value.if_version_match,
683
+ if_version_not_match: value.if_version_not_match,
684
+ if_modified_since: value.if_modified_since,
685
+ if_unmodified_since: value.if_unmodified_since,
686
+ content_length_hint: value.content_length_hint,
687
+ ..Default::default()
688
+ };
689
+ (OpRead::from_read_options(read), reader)
552
690
  }
553
691
  }
554
692
 
555
693
  /// Arguments for `stat` operation.
556
694
  #[derive(Debug, Clone, Default)]
557
695
  pub struct OpStat {
558
- if_match: Option<String>,
559
- if_none_match: Option<String>,
560
- if_modified_since: Option<Timestamp>,
561
- if_unmodified_since: Option<Timestamp>,
562
- override_content_type: Option<String>,
563
- override_cache_control: Option<String>,
564
- override_content_disposition: Option<String>,
565
- version: Option<String>,
696
+ values: CompactValues,
566
697
  }
567
698
 
568
699
  impl OpStat {
@@ -571,107 +702,111 @@ impl OpStat {
571
702
  Self::default()
572
703
  }
573
704
 
574
- /// Set the If-Match of the option
575
- pub fn with_if_match(mut self, if_match: &str) -> Self {
576
- self.if_match = Some(if_match.to_string());
577
- self
578
- }
579
-
580
705
  /// Get If-Match from option
706
+ #[inline]
581
707
  pub fn if_match(&self) -> Option<&str> {
582
- self.if_match.as_deref()
583
- }
584
-
585
- /// Set the If-None-Match of the option
586
- pub fn with_if_none_match(mut self, if_none_match: &str) -> Self {
587
- self.if_none_match = Some(if_none_match.to_string());
588
- self
708
+ string_value(&self.values, ReadField::IfMatch as usize)
589
709
  }
590
710
 
591
711
  /// Get If-None-Match from option
712
+ #[inline]
592
713
  pub fn if_none_match(&self) -> Option<&str> {
593
- self.if_none_match.as_deref()
714
+ string_value(&self.values, ReadField::IfNoneMatch as usize)
594
715
  }
595
716
 
596
- /// Set the If-Modified-Since of the option
597
- pub fn with_if_modified_since(mut self, v: Timestamp) -> Self {
598
- self.if_modified_since = Some(v);
599
- self
717
+ /// Get the version match condition.
718
+ #[inline]
719
+ pub fn if_version_match(&self) -> Option<&str> {
720
+ string_value(&self.values, ReadField::IfVersionMatch as usize)
600
721
  }
601
722
 
602
- /// Get If-Modified-Since from option
603
- pub fn if_modified_since(&self) -> Option<Timestamp> {
604
- self.if_modified_since
723
+ /// Get the version non-match condition.
724
+ #[inline]
725
+ pub fn if_version_not_match(&self) -> Option<&str> {
726
+ string_value(&self.values, ReadField::IfVersionNotMatch as usize)
605
727
  }
606
728
 
607
- /// Set the If-Unmodified-Since of the option
608
- pub fn with_if_unmodified_since(mut self, v: Timestamp) -> Self {
609
- self.if_unmodified_since = Some(v);
610
- self
729
+ /// Get If-Modified-Since from option
730
+ #[inline]
731
+ pub fn if_modified_since(&self) -> Option<Timestamp> {
732
+ self.values
733
+ .get(ReadField::IfModifiedSince as usize)
734
+ .map(decode_timestamp)
611
735
  }
612
736
 
613
737
  /// Get If-Unmodified-Since from option
738
+ #[inline]
614
739
  pub fn if_unmodified_since(&self) -> Option<Timestamp> {
615
- self.if_unmodified_since
740
+ self.values
741
+ .get(ReadField::IfUnmodifiedSince as usize)
742
+ .map(decode_timestamp)
616
743
  }
617
744
 
618
- /// Sets the content-disposition header that should be sent back by the remote read operation.
619
- pub fn with_override_content_disposition(mut self, content_disposition: &str) -> Self {
620
- self.override_content_disposition = Some(content_disposition.into());
621
- self
745
+ /// Returns whether at least one value-bearing conditional option is set.
746
+ #[inline]
747
+ pub fn is_conditional(&self) -> bool {
748
+ self.if_match().is_some()
749
+ || self.if_none_match().is_some()
750
+ || self.if_version_match().is_some()
751
+ || self.if_version_not_match().is_some()
752
+ || self.if_modified_since().is_some()
753
+ || self.if_unmodified_since().is_some()
622
754
  }
623
755
 
624
756
  /// Returns the content-disposition header that should be sent back by the remote read
625
757
  /// operation.
758
+ #[inline]
626
759
  pub fn override_content_disposition(&self) -> Option<&str> {
627
- self.override_content_disposition.as_deref()
628
- }
629
-
630
- /// Sets the cache-control header that should be sent back by the remote read operation.
631
- pub fn with_override_cache_control(mut self, cache_control: &str) -> Self {
632
- self.override_cache_control = Some(cache_control.into());
633
- self
760
+ string_value(&self.values, ReadField::OverrideContentDisposition as usize)
634
761
  }
635
762
 
636
763
  /// Returns the cache-control header that should be sent back by the remote read operation.
764
+ #[inline]
637
765
  pub fn override_cache_control(&self) -> Option<&str> {
638
- self.override_cache_control.as_deref()
639
- }
640
-
641
- /// Sets the content-type header that should be sent back by the remote read operation.
642
- pub fn with_override_content_type(mut self, content_type: &str) -> Self {
643
- self.override_content_type = Some(content_type.into());
644
- self
766
+ string_value(&self.values, ReadField::OverrideCacheControl as usize)
645
767
  }
646
768
 
647
769
  /// Returns the content-type header that should be sent back by the remote read operation.
770
+ #[inline]
648
771
  pub fn override_content_type(&self) -> Option<&str> {
649
- self.override_content_type.as_deref()
650
- }
651
-
652
- /// Set the version of the option
653
- pub fn with_version(mut self, version: &str) -> Self {
654
- self.version = Some(version.to_string());
655
- self
772
+ string_value(&self.values, ReadField::OverrideContentType as usize)
656
773
  }
657
774
 
658
775
  /// Get version from option
776
+ #[inline]
659
777
  pub fn version(&self) -> Option<&str> {
660
- self.version.as_deref()
778
+ string_value(&self.values, ReadField::Version as usize)
779
+ }
780
+
781
+ pub(crate) fn from_read(value: &OpRead) -> Self {
782
+ // `OpStat` uses the same `ReadField` layout and simply ignores the
783
+ // read-only content-length hint.
784
+ Self {
785
+ values: value.values.clone(),
786
+ }
661
787
  }
662
788
  }
663
789
 
664
790
  impl From<options::StatOptions> for OpStat {
665
791
  fn from(value: options::StatOptions) -> Self {
792
+ let if_modified_since = value.if_modified_since.map(encode_timestamp);
793
+ let if_unmodified_since = value.if_unmodified_since.map(encode_timestamp);
666
794
  Self {
667
- if_match: value.if_match,
668
- if_none_match: value.if_none_match,
669
- if_modified_since: value.if_modified_since,
670
- if_unmodified_since: value.if_unmodified_since,
671
- override_content_type: value.override_content_type,
672
- override_cache_control: value.override_cache_control,
673
- override_content_disposition: value.override_content_disposition,
674
- version: value.version,
795
+ values: CompactValues::encode(&[
796
+ value.if_match.as_deref().map(str::as_bytes),
797
+ value.if_none_match.as_deref().map(str::as_bytes),
798
+ value.if_version_match.as_deref().map(str::as_bytes),
799
+ value.if_version_not_match.as_deref().map(str::as_bytes),
800
+ if_modified_since.as_ref().map(|value| value.as_slice()),
801
+ if_unmodified_since.as_ref().map(|value| value.as_slice()),
802
+ value.override_content_type.as_deref().map(str::as_bytes),
803
+ value.override_cache_control.as_deref().map(str::as_bytes),
804
+ value
805
+ .override_content_disposition
806
+ .as_deref()
807
+ .map(str::as_bytes),
808
+ value.version.as_deref().map(str::as_bytes),
809
+ ]),
675
810
  }
676
811
  }
677
812
  }
@@ -679,16 +814,25 @@ impl From<options::StatOptions> for OpStat {
679
814
  /// Arguments for `write` operation.
680
815
  #[derive(Debug, Clone, Default)]
681
816
  pub struct OpWrite {
682
- append: bool,
683
817
  concurrent: usize,
684
- content_type: Option<String>,
685
- content_disposition: Option<String>,
686
- content_encoding: Option<String>,
687
- cache_control: Option<String>,
688
- if_match: Option<String>,
689
- if_none_match: Option<String>,
690
- if_not_exists: bool,
691
- user_metadata: Option<HashMap<String, String>>,
818
+ flags: u8,
819
+ values: CompactValues,
820
+ }
821
+
822
+ const OP_WRITE_APPEND: u8 = 1;
823
+ const OP_WRITE_IF_NOT_EXISTS: u8 = 1 << 1;
824
+
825
+ #[repr(usize)]
826
+ enum WriteField {
827
+ ContentType,
828
+ ContentDisposition,
829
+ ContentEncoding,
830
+ CacheControl,
831
+ IfMatch,
832
+ IfNoneMatch,
833
+ IfVersionMatch,
834
+ IfVersionNotMatch,
835
+ UserMetadata,
692
836
  }
693
837
 
694
838
  impl OpWrite {
@@ -699,122 +843,188 @@ impl OpWrite {
699
843
  Self::default()
700
844
  }
701
845
 
702
- /// Get the append from op.
846
+ /// Lower `options` against `capability` and freeze them into service-ready arguments.
703
847
  ///
704
- /// The append is the flag to indicate that this write operation is an append operation.
705
- pub fn append(&self) -> bool {
706
- self.append
707
- }
708
-
709
- /// Set the append mode of op.
848
+ /// # Errors
710
849
  ///
711
- /// If the append mode is set, the data will be appended to the end of the file.
850
+ /// Returns an error when `if_not_changed` contains no identity or conflicts
851
+ /// with an explicit equality condition.
712
852
  ///
713
- /// # Notes
853
+ /// # Panics
714
854
  ///
715
- /// Service could return `Unsupported` if the storage does not support append.
716
- pub fn with_append(mut self, append: bool) -> Self {
717
- self.append = append;
718
- self
855
+ /// Panics when the compact value block, including its index, exceeds `u16::MAX` bytes.
856
+ pub fn from_options(
857
+ capability: &Capability,
858
+ mut options: options::WriteOptions,
859
+ ) -> Result<(Self, OpWriter)> {
860
+ if let Some(metadata) = options.if_not_changed.take() {
861
+ let (target, identity, name) = if capability.write_with_if_version_match
862
+ && let Some(version) = metadata.version()
863
+ {
864
+ (&mut options.if_version_match, version, "if_version_match")
865
+ } else if let Some(etag) = metadata.etag() {
866
+ (&mut options.if_match, etag, "if_match")
867
+ } else if let Some(version) = metadata.version() {
868
+ (&mut options.if_version_match, version, "if_version_match")
869
+ } else {
870
+ return Err(Error::new(
871
+ ErrorKind::ConfigInvalid,
872
+ "if_not_changed metadata contains neither version nor ETag",
873
+ )
874
+ .with_operation(Operation::Write));
875
+ };
876
+
877
+ if let Some(explicit) = target {
878
+ if explicit != identity {
879
+ return Err(Error::new(
880
+ ErrorKind::ConditionNotMatch,
881
+ format!("if_not_changed conflicts with {name}"),
882
+ )
883
+ .with_operation(Operation::Write));
884
+ }
885
+ } else {
886
+ *target = Some(identity.to_owned());
887
+ }
888
+ }
889
+
890
+ let writer = OpWriter {
891
+ chunk: options.chunk,
892
+ };
893
+ let user_metadata = options.user_metadata.take().map(sorted_user_metadata);
894
+ let mut flags = 0;
895
+ if options.append {
896
+ flags |= OP_WRITE_APPEND;
897
+ }
898
+ if options.if_not_exists {
899
+ flags |= OP_WRITE_IF_NOT_EXISTS;
900
+ }
901
+ let fields = [
902
+ options.content_type.as_deref().map(str::as_bytes),
903
+ options.content_disposition.as_deref().map(str::as_bytes),
904
+ options.content_encoding.as_deref().map(str::as_bytes),
905
+ options.cache_control.as_deref().map(str::as_bytes),
906
+ options.if_match.as_deref().map(str::as_bytes),
907
+ options.if_none_match.as_deref().map(str::as_bytes),
908
+ options.if_version_match.as_deref().map(str::as_bytes),
909
+ options.if_version_not_match.as_deref().map(str::as_bytes),
910
+ None,
911
+ ];
912
+ let mut lengths = fields.map(|value| value.map(<[u8]>::len));
913
+ lengths[WriteField::UserMetadata as usize] =
914
+ user_metadata.as_deref().map(user_metadata_encoded_len);
915
+ let args = Self {
916
+ concurrent: options.concurrent.max(1),
917
+ flags,
918
+ values: CompactValues::encode_with(&lengths, |field, output| match field {
919
+ field if field == WriteField::UserMetadata as usize => {
920
+ write_user_metadata(
921
+ user_metadata.as_deref().expect("present field has a value"),
922
+ output,
923
+ );
924
+ }
925
+ _ => {
926
+ output.write(fields[field].expect("present field has a value"));
927
+ }
928
+ }),
929
+ };
930
+ Ok((args, writer))
719
931
  }
720
932
 
721
- /// Get the content type from option
722
- pub fn content_type(&self) -> Option<&str> {
723
- self.content_type.as_deref()
933
+ /// Get the append from op.
934
+ ///
935
+ /// The append is the flag to indicate that this write operation is an append operation.
936
+ #[inline]
937
+ pub fn append(&self) -> bool {
938
+ self.flags & OP_WRITE_APPEND != 0
724
939
  }
725
940
 
726
- /// Set the content type of option
727
- pub fn with_content_type(mut self, content_type: &str) -> Self {
728
- self.content_type = Some(content_type.to_string());
729
- self
941
+ /// Get the content type from option
942
+ #[inline]
943
+ pub fn content_type(&self) -> Option<&str> {
944
+ string_value(&self.values, WriteField::ContentType as usize)
730
945
  }
731
946
 
732
947
  /// Get the content disposition from option
948
+ #[inline]
733
949
  pub fn content_disposition(&self) -> Option<&str> {
734
- self.content_disposition.as_deref()
735
- }
736
-
737
- /// Set the content disposition of option
738
- pub fn with_content_disposition(mut self, content_disposition: &str) -> Self {
739
- self.content_disposition = Some(content_disposition.to_string());
740
- self
950
+ string_value(&self.values, WriteField::ContentDisposition as usize)
741
951
  }
742
952
 
743
953
  /// Get the content encoding from option
954
+ #[inline]
744
955
  pub fn content_encoding(&self) -> Option<&str> {
745
- self.content_encoding.as_deref()
746
- }
747
-
748
- /// Set the content encoding of option
749
- pub fn with_content_encoding(mut self, content_encoding: &str) -> Self {
750
- self.content_encoding = Some(content_encoding.to_string());
751
- self
956
+ string_value(&self.values, WriteField::ContentEncoding as usize)
752
957
  }
753
958
 
754
959
  /// Get the cache control from option
960
+ #[inline]
755
961
  pub fn cache_control(&self) -> Option<&str> {
756
- self.cache_control.as_deref()
757
- }
758
-
759
- /// Set the content type of option
760
- pub fn with_cache_control(mut self, cache_control: &str) -> Self {
761
- self.cache_control = Some(cache_control.to_string());
762
- self
962
+ string_value(&self.values, WriteField::CacheControl as usize)
763
963
  }
764
964
 
765
965
  /// Get the concurrent.
966
+ #[inline]
766
967
  pub fn concurrent(&self) -> usize {
767
968
  self.concurrent
768
969
  }
769
970
 
770
- /// Set the maximum concurrent write task amount.
771
- pub fn with_concurrent(mut self, concurrent: usize) -> Self {
772
- self.concurrent = concurrent;
773
- self
774
- }
775
-
776
- /// Set the If-Match of the option
777
- pub fn with_if_match(mut self, s: &str) -> Self {
778
- self.if_match = Some(s.to_string());
779
- self
780
- }
781
-
782
971
  /// Get If-Match from option
972
+ #[inline]
783
973
  pub fn if_match(&self) -> Option<&str> {
784
- self.if_match.as_deref()
785
- }
786
-
787
- /// Set the If-None-Match of the option
788
- pub fn with_if_none_match(mut self, s: &str) -> Self {
789
- self.if_none_match = Some(s.to_string());
790
- self
974
+ string_value(&self.values, WriteField::IfMatch as usize)
791
975
  }
792
976
 
793
977
  /// Get If-None-Match from option
978
+ #[inline]
794
979
  pub fn if_none_match(&self) -> Option<&str> {
795
- self.if_none_match.as_deref()
980
+ string_value(&self.values, WriteField::IfNoneMatch as usize)
796
981
  }
797
982
 
798
- /// Set the If-Not-Exist of the option
799
- pub fn with_if_not_exists(mut self, b: bool) -> Self {
800
- self.if_not_exists = b;
801
- self
983
+ /// Get the version match condition.
984
+ #[inline]
985
+ pub fn if_version_match(&self) -> Option<&str> {
986
+ string_value(&self.values, WriteField::IfVersionMatch as usize)
987
+ }
988
+
989
+ /// Get the version non-match condition.
990
+ #[inline]
991
+ pub fn if_version_not_match(&self) -> Option<&str> {
992
+ string_value(&self.values, WriteField::IfVersionNotMatch as usize)
802
993
  }
803
994
 
804
995
  /// Get If-Not-Exist from option
996
+ #[inline]
805
997
  pub fn if_not_exists(&self) -> bool {
806
- self.if_not_exists
998
+ self.flags & OP_WRITE_IF_NOT_EXISTS != 0
807
999
  }
808
1000
 
809
- /// Set the user defined metadata of the op
810
- pub fn with_user_metadata(mut self, metadata: HashMap<String, String>) -> Self {
811
- self.user_metadata = Some(metadata);
812
- self
1001
+ /// Returns whether at least one conditional option is set.
1002
+ ///
1003
+ /// Value-bearing options are set when present. Boolean options are set only
1004
+ /// when their value is `true`.
1005
+ #[inline]
1006
+ pub fn is_conditional(&self) -> bool {
1007
+ self.if_not_exists()
1008
+ || self.if_match().is_some()
1009
+ || self.if_none_match().is_some()
1010
+ || self.if_version_match().is_some()
1011
+ || self.if_version_not_match().is_some()
813
1012
  }
814
1013
 
815
1014
  /// Get the user defined metadata from the op
816
- pub fn user_metadata(&self) -> Option<&HashMap<String, String>> {
817
- self.user_metadata.as_ref()
1015
+ #[inline]
1016
+ pub fn user_metadata(&self) -> Option<UserMetadata<'_>> {
1017
+ self.values
1018
+ .get(WriteField::UserMetadata as usize)
1019
+ .map(UserMetadata::new)
1020
+ }
1021
+
1022
+ #[doc(hidden)]
1023
+ pub fn into_content_type(mut self, value: &str) -> Self {
1024
+ self.values = self
1025
+ .values
1026
+ .replace(WriteField::ContentType as usize, value.as_bytes());
1027
+ self
818
1028
  }
819
1029
  }
820
1030
 
@@ -852,145 +1062,347 @@ impl OpWriter {
852
1062
  }
853
1063
  }
854
1064
 
855
- impl From<options::WriteOptions> for (OpWrite, OpWriter) {
856
- fn from(value: options::WriteOptions) -> Self {
857
- (
858
- OpWrite {
859
- append: value.append,
860
- // Ensure concurrent is at least 1
861
- concurrent: value.concurrent.max(1),
862
- content_type: value.content_type,
863
- content_disposition: value.content_disposition,
864
- content_encoding: value.content_encoding,
865
- cache_control: value.cache_control,
866
- if_match: value.if_match,
867
- if_none_match: value.if_none_match,
868
- if_not_exists: value.if_not_exists,
869
- user_metadata: value.user_metadata,
870
- },
871
- OpWriter { chunk: value.chunk },
872
- )
873
- }
1065
+ /// Arguments for `compose` operation.
1066
+ #[derive(Debug, Clone, Default)]
1067
+ pub struct OpCompose {
1068
+ concurrent: usize,
1069
+ flags: u8,
1070
+ values: CompactValues,
874
1071
  }
875
1072
 
876
- /// Arguments for `copy` operation.
877
- #[derive(Debug, Clone, Default)]
878
- pub struct OpCopy {
879
- if_not_exists: bool,
880
- if_match: Option<String>,
881
- source_version: Option<String>,
1073
+ const OP_COMPOSE_IF_NOT_EXISTS: u8 = 1;
1074
+
1075
+ #[repr(usize)]
1076
+ enum ComposeField {
1077
+ ContentType,
1078
+ ContentDisposition,
1079
+ ContentEncoding,
1080
+ CacheControl,
1081
+ IfMatch,
1082
+ IfNoneMatch,
1083
+ IfVersionMatch,
1084
+ IfVersionNotMatch,
1085
+ UserMetadata,
882
1086
  }
883
1087
 
884
- impl OpCopy {
885
- /// Create a new `OpCopy`.
1088
+ impl OpCompose {
1089
+ /// Create a new `OpCompose`.
886
1090
  pub fn new() -> Self {
887
1091
  Self::default()
888
1092
  }
889
1093
 
890
- /// Set the if_not_exists flag for the operation.
1094
+ /// Lower `options` against `capability` and freeze them into service-ready arguments.
891
1095
  ///
892
- /// When set to true, the copy operation will only proceed if the destination
893
- /// doesn't already exist.
894
- pub fn with_if_not_exists(mut self, if_not_exists: bool) -> Self {
895
- self.if_not_exists = if_not_exists;
896
- self
1096
+ /// # Errors
1097
+ ///
1098
+ /// Returns an error when `if_not_changed` contains no identity or conflicts
1099
+ /// with an explicit equality condition.
1100
+ ///
1101
+ /// # Panics
1102
+ ///
1103
+ /// Panics when the compact value block, including its index, exceeds `u16::MAX` bytes.
1104
+ pub fn from_options(
1105
+ capability: &Capability,
1106
+ mut options: options::ComposeOptions,
1107
+ ) -> Result<Self> {
1108
+ if let Some(metadata) = options.if_not_changed.take() {
1109
+ let (target, identity, name) = if capability.compose_with_if_version_match
1110
+ && let Some(version) = metadata.version()
1111
+ {
1112
+ (&mut options.if_version_match, version, "if_version_match")
1113
+ } else if let Some(etag) = metadata.etag() {
1114
+ (&mut options.if_match, etag, "if_match")
1115
+ } else if let Some(version) = metadata.version() {
1116
+ (&mut options.if_version_match, version, "if_version_match")
1117
+ } else {
1118
+ return Err(Error::new(
1119
+ ErrorKind::ConfigInvalid,
1120
+ "if_not_changed metadata contains neither version nor ETag",
1121
+ )
1122
+ .with_operation(Operation::Compose));
1123
+ };
1124
+
1125
+ if let Some(explicit) = target {
1126
+ if explicit != identity {
1127
+ return Err(Error::new(
1128
+ ErrorKind::ConditionNotMatch,
1129
+ format!("if_not_changed conflicts with {name}"),
1130
+ )
1131
+ .with_operation(Operation::Compose));
1132
+ }
1133
+ } else {
1134
+ *target = Some(identity.to_owned());
1135
+ }
1136
+ }
1137
+
1138
+ let user_metadata = options.user_metadata.take().map(sorted_user_metadata);
1139
+ let fields = [
1140
+ options.content_type.as_deref().map(str::as_bytes),
1141
+ options.content_disposition.as_deref().map(str::as_bytes),
1142
+ options.content_encoding.as_deref().map(str::as_bytes),
1143
+ options.cache_control.as_deref().map(str::as_bytes),
1144
+ options.if_match.as_deref().map(str::as_bytes),
1145
+ options.if_none_match.as_deref().map(str::as_bytes),
1146
+ options.if_version_match.as_deref().map(str::as_bytes),
1147
+ options.if_version_not_match.as_deref().map(str::as_bytes),
1148
+ None,
1149
+ ];
1150
+ let mut lengths = fields.map(|value| value.map(<[u8]>::len));
1151
+ lengths[ComposeField::UserMetadata as usize] =
1152
+ user_metadata.as_deref().map(user_metadata_encoded_len);
1153
+ Ok(Self {
1154
+ concurrent: options.concurrent.max(1),
1155
+ flags: if options.if_not_exists {
1156
+ OP_COMPOSE_IF_NOT_EXISTS
1157
+ } else {
1158
+ 0
1159
+ },
1160
+ values: CompactValues::encode_with(&lengths, |field, output| match field {
1161
+ field if field == ComposeField::UserMetadata as usize => {
1162
+ write_user_metadata(
1163
+ user_metadata.as_deref().expect("present field has a value"),
1164
+ output,
1165
+ );
1166
+ }
1167
+ _ => {
1168
+ output.write(fields[field].expect("present field has a value"));
1169
+ }
1170
+ }),
1171
+ })
1172
+ }
1173
+
1174
+ /// Get the maximum concurrent composition task count.
1175
+ pub fn concurrent(&self) -> usize {
1176
+ self.concurrent.max(1)
897
1177
  }
898
1178
 
899
- /// Get if_not_exists flag.
900
- pub fn if_not_exists(&self) -> bool {
901
- self.if_not_exists
1179
+ /// Get destination Content-Type metadata.
1180
+ pub fn content_type(&self) -> Option<&str> {
1181
+ string_value(&self.values, ComposeField::ContentType as usize)
902
1182
  }
903
1183
 
904
- /// Set the if_match condition for the operation.
905
- ///
906
- /// When set, the copy operation will only proceed if the existing destination
907
- /// object's ETag matches the given value.
908
- pub fn with_if_match(mut self, if_match: impl Into<String>) -> Self {
909
- self.if_match = Some(if_match.into());
910
- self
1184
+ /// Get destination Content-Disposition metadata.
1185
+ pub fn content_disposition(&self) -> Option<&str> {
1186
+ string_value(&self.values, ComposeField::ContentDisposition as usize)
911
1187
  }
912
1188
 
913
- /// Get if_match condition.
1189
+ /// Get destination Content-Encoding metadata.
1190
+ pub fn content_encoding(&self) -> Option<&str> {
1191
+ string_value(&self.values, ComposeField::ContentEncoding as usize)
1192
+ }
1193
+
1194
+ /// Get destination Cache-Control metadata.
1195
+ pub fn cache_control(&self) -> Option<&str> {
1196
+ string_value(&self.values, ComposeField::CacheControl as usize)
1197
+ }
1198
+
1199
+ /// Get destination user metadata.
1200
+ pub fn user_metadata(&self) -> Option<UserMetadata<'_>> {
1201
+ self.values
1202
+ .get(ComposeField::UserMetadata as usize)
1203
+ .map(UserMetadata::new)
1204
+ }
1205
+
1206
+ /// Get the destination ETag match condition.
914
1207
  pub fn if_match(&self) -> Option<&str> {
915
- self.if_match.as_deref()
1208
+ string_value(&self.values, ComposeField::IfMatch as usize)
916
1209
  }
917
1210
 
918
- /// Set source version for the operation.
919
- ///
920
- /// When set, the copy operation will copy from the specified source version.
921
- pub fn with_source_version(mut self, version: impl Into<String>) -> Self {
922
- self.source_version = Some(version.into());
923
- self
1211
+ /// Get the destination ETag non-match condition.
1212
+ pub fn if_none_match(&self) -> Option<&str> {
1213
+ string_value(&self.values, ComposeField::IfNoneMatch as usize)
924
1214
  }
925
1215
 
926
- /// Get source version from the operation.
927
- pub fn source_version(&self) -> Option<&str> {
928
- self.source_version.as_deref()
1216
+ /// Get the destination version match condition.
1217
+ pub fn if_version_match(&self) -> Option<&str> {
1218
+ string_value(&self.values, ComposeField::IfVersionMatch as usize)
1219
+ }
1220
+
1221
+ /// Get the destination version non-match condition.
1222
+ pub fn if_version_not_match(&self) -> Option<&str> {
1223
+ string_value(&self.values, ComposeField::IfVersionNotMatch as usize)
1224
+ }
1225
+
1226
+ /// Get whether composition requires a missing destination.
1227
+ pub fn if_not_exists(&self) -> bool {
1228
+ self.flags & OP_COMPOSE_IF_NOT_EXISTS != 0
1229
+ }
1230
+
1231
+ /// Returns whether at least one conditional option is set.
1232
+ ///
1233
+ /// Value-bearing options are set when present. Boolean options are set only
1234
+ /// when their value is `true`.
1235
+ #[inline]
1236
+ pub fn is_conditional(&self) -> bool {
1237
+ self.if_not_exists()
1238
+ || self.if_match().is_some()
1239
+ || self.if_none_match().is_some()
1240
+ || self.if_version_match().is_some()
1241
+ || self.if_version_not_match().is_some()
1242
+ }
1243
+
1244
+ #[doc(hidden)]
1245
+ pub fn into_content_type(mut self, value: &str) -> Self {
1246
+ self.values = self
1247
+ .values
1248
+ .replace(ComposeField::ContentType as usize, value.as_bytes());
1249
+ self
929
1250
  }
930
1251
  }
931
1252
 
932
- /// Arguments for `copier` operation.
1253
+ /// Arguments for `copy` operation.
933
1254
  #[derive(Debug, Clone, Default)]
934
- pub struct OpCopier {
1255
+ pub struct OpCopy {
935
1256
  concurrent: usize,
936
1257
  chunk: Option<usize>,
937
1258
  source_content_length_hint: Option<u64>,
1259
+ flags: u8,
1260
+ values: CompactValues,
1261
+ }
1262
+
1263
+ const OP_COPY_IF_NOT_EXISTS: u8 = 1;
1264
+
1265
+ #[repr(usize)]
1266
+ enum CopyField {
1267
+ IfMatch,
1268
+ IfNoneMatch,
1269
+ IfVersionMatch,
1270
+ IfVersionNotMatch,
1271
+ SourceVersion,
938
1272
  }
939
1273
 
940
- impl OpCopier {
941
- /// Create a new `OpCopier`.
1274
+ impl OpCopy {
1275
+ /// Create a new `OpCopy`.
942
1276
  pub fn new() -> Self {
943
1277
  Self::default()
944
1278
  }
945
1279
 
946
- /// Set the concurrent tasks for the copier.
947
- pub fn with_concurrent(mut self, concurrent: usize) -> Self {
948
- self.concurrent = concurrent.max(1);
949
- self
1280
+ /// Lower `options` against `capability` and freeze them into service-ready arguments.
1281
+ ///
1282
+ /// # Errors
1283
+ ///
1284
+ /// Returns an error when `if_not_changed` contains no identity or conflicts
1285
+ /// with an explicit equality condition.
1286
+ ///
1287
+ /// # Panics
1288
+ ///
1289
+ /// Panics when the compact value block, including its index, exceeds `u16::MAX` bytes.
1290
+ pub fn from_options(
1291
+ capability: &Capability,
1292
+ mut options: options::CopyOptions,
1293
+ ) -> Result<Self> {
1294
+ if let Some(metadata) = options.if_not_changed.take() {
1295
+ let (target, identity, name) = if capability.copy_with_if_version_match
1296
+ && let Some(version) = metadata.version()
1297
+ {
1298
+ (&mut options.if_version_match, version, "if_version_match")
1299
+ } else if let Some(etag) = metadata.etag() {
1300
+ (&mut options.if_match, etag, "if_match")
1301
+ } else if let Some(version) = metadata.version() {
1302
+ (&mut options.if_version_match, version, "if_version_match")
1303
+ } else {
1304
+ return Err(Error::new(
1305
+ ErrorKind::ConfigInvalid,
1306
+ "if_not_changed metadata contains neither version nor ETag",
1307
+ )
1308
+ .with_operation(Operation::Copy));
1309
+ };
1310
+
1311
+ if let Some(explicit) = target {
1312
+ if explicit != identity {
1313
+ return Err(Error::new(
1314
+ ErrorKind::ConditionNotMatch,
1315
+ format!("if_not_changed conflicts with {name}"),
1316
+ )
1317
+ .with_operation(Operation::Copy));
1318
+ }
1319
+ } else {
1320
+ *target = Some(identity.to_owned());
1321
+ }
1322
+ }
1323
+
1324
+ let fields = [
1325
+ options.if_match.as_deref().map(str::as_bytes),
1326
+ options.if_none_match.as_deref().map(str::as_bytes),
1327
+ options.if_version_match.as_deref().map(str::as_bytes),
1328
+ options.if_version_not_match.as_deref().map(str::as_bytes),
1329
+ options.source_version.as_deref().map(str::as_bytes),
1330
+ ];
1331
+ Ok(Self {
1332
+ concurrent: options.concurrent.max(1),
1333
+ chunk: options.chunk,
1334
+ source_content_length_hint: options.source_content_length_hint,
1335
+ flags: if options.if_not_exists {
1336
+ OP_COPY_IF_NOT_EXISTS
1337
+ } else {
1338
+ 0
1339
+ },
1340
+ values: CompactValues::encode(&fields),
1341
+ })
950
1342
  }
951
1343
 
952
- /// Get the concurrent tasks for the copier.
953
- pub fn concurrent(&self) -> usize {
954
- self.concurrent.max(1)
1344
+ /// Get if_not_exists flag.
1345
+ #[inline]
1346
+ pub fn if_not_exists(&self) -> bool {
1347
+ self.flags & OP_COPY_IF_NOT_EXISTS != 0
955
1348
  }
956
1349
 
957
- /// Set the chunk size for the copier.
958
- pub fn with_chunk(mut self, chunk: usize) -> Self {
959
- self.chunk = Some(chunk);
960
- self
1350
+ /// Get if_match condition.
1351
+ #[inline]
1352
+ pub fn if_match(&self) -> Option<&str> {
1353
+ string_value(&self.values, CopyField::IfMatch as usize)
961
1354
  }
962
1355
 
963
- /// Get the chunk size for the copier.
964
- pub fn chunk(&self) -> Option<usize> {
965
- self.chunk
1356
+ /// Get the destination ETag non-match condition.
1357
+ #[inline]
1358
+ pub fn if_none_match(&self) -> Option<&str> {
1359
+ string_value(&self.values, CopyField::IfNoneMatch as usize)
966
1360
  }
967
1361
 
968
- /// Set source content length hint for the copier.
969
- pub fn with_source_content_length_hint(mut self, content_length: u64) -> Self {
970
- self.source_content_length_hint = Some(content_length);
971
- self
1362
+ /// Get the current destination version match condition.
1363
+ #[inline]
1364
+ pub fn if_version_match(&self) -> Option<&str> {
1365
+ string_value(&self.values, CopyField::IfVersionMatch as usize)
972
1366
  }
973
1367
 
974
- /// Get source content length hint from the copier.
975
- pub fn source_content_length_hint(&self) -> Option<u64> {
976
- self.source_content_length_hint
1368
+ /// Get the current destination version non-match condition.
1369
+ #[inline]
1370
+ pub fn if_version_not_match(&self) -> Option<&str> {
1371
+ string_value(&self.values, CopyField::IfVersionNotMatch as usize)
977
1372
  }
978
- }
979
1373
 
980
- impl From<options::CopyOptions> for (OpCopy, OpCopier) {
981
- fn from(value: options::CopyOptions) -> Self {
982
- (
983
- OpCopy {
984
- if_not_exists: value.if_not_exists,
985
- if_match: value.if_match,
986
- source_version: value.source_version,
987
- },
988
- OpCopier {
989
- concurrent: value.concurrent.max(1),
990
- chunk: value.chunk,
991
- source_content_length_hint: value.source_content_length_hint,
992
- },
993
- )
1374
+ /// Returns whether at least one conditional option is set.
1375
+ ///
1376
+ /// Value-bearing options are set when present. Boolean options are set only
1377
+ /// when their value is `true`.
1378
+ #[inline]
1379
+ pub fn is_conditional(&self) -> bool {
1380
+ self.if_not_exists()
1381
+ || self.if_match().is_some()
1382
+ || self.if_none_match().is_some()
1383
+ || self.if_version_match().is_some()
1384
+ || self.if_version_not_match().is_some()
1385
+ }
1386
+
1387
+ /// Get source version from the operation.
1388
+ #[inline]
1389
+ pub fn source_version(&self) -> Option<&str> {
1390
+ string_value(&self.values, CopyField::SourceVersion as usize)
1391
+ }
1392
+
1393
+ /// Get the concurrent tasks for the copy operation.
1394
+ pub fn concurrent(&self) -> usize {
1395
+ self.concurrent.max(1)
1396
+ }
1397
+
1398
+ /// Get the chunk size for the copy operation.
1399
+ pub fn chunk(&self) -> Option<usize> {
1400
+ self.chunk
1401
+ }
1402
+
1403
+ /// Get source content length hint from the copy operation.
1404
+ pub fn source_content_length_hint(&self) -> Option<u64> {
1405
+ self.source_content_length_hint
994
1406
  }
995
1407
  }
996
1408
 
@@ -1029,6 +1441,12 @@ impl OpRename {
1029
1441
  pub fn if_not_exists(&self) -> bool {
1030
1442
  self.if_not_exists
1031
1443
  }
1444
+
1445
+ /// Returns whether the boolean conditional option is set to `true`.
1446
+ #[inline]
1447
+ pub fn is_conditional(&self) -> bool {
1448
+ self.if_not_exists()
1449
+ }
1032
1450
  }
1033
1451
 
1034
1452
  impl From<options::RenameOptions> for OpRename {
@@ -1038,3 +1456,320 @@ impl From<options::RenameOptions> for OpRename {
1038
1456
  }
1039
1457
  }
1040
1458
  }
1459
+
1460
+ /// Arguments for `restore` operation.
1461
+ #[derive(Debug, Clone, Default)]
1462
+ pub struct OpRestore {
1463
+ flags: u8,
1464
+ values: CompactValues,
1465
+ }
1466
+
1467
+ const OP_RESTORE_IF_NOT_EXISTS: u8 = 1;
1468
+
1469
+ impl OpRestore {
1470
+ /// Create a new `OpRestore`.
1471
+ pub fn new() -> Self {
1472
+ Self::default()
1473
+ }
1474
+
1475
+ /// Return the version to restore.
1476
+ #[inline]
1477
+ pub fn version(&self) -> Option<&str> {
1478
+ string_value(&self.values, 0)
1479
+ }
1480
+
1481
+ /// Return whether the restore should fail if the path currently exists.
1482
+ #[inline]
1483
+ pub fn if_not_exists(&self) -> bool {
1484
+ self.flags & OP_RESTORE_IF_NOT_EXISTS != 0
1485
+ }
1486
+
1487
+ /// Returns whether the boolean conditional option is set to `true`.
1488
+ #[inline]
1489
+ pub fn is_conditional(&self) -> bool {
1490
+ self.if_not_exists()
1491
+ }
1492
+ }
1493
+
1494
+ impl From<options::RestoreOptions> for OpRestore {
1495
+ fn from(value: options::RestoreOptions) -> Self {
1496
+ Self {
1497
+ flags: if value.if_not_exists {
1498
+ OP_RESTORE_IF_NOT_EXISTS
1499
+ } else {
1500
+ 0
1501
+ },
1502
+ values: CompactValues::encode(&[value.version.as_deref().map(str::as_bytes)]),
1503
+ }
1504
+ }
1505
+ }
1506
+
1507
+ #[cfg(test)]
1508
+ mod tests {
1509
+ use super::*;
1510
+ use crate::Metadata;
1511
+ use crate::MetadataBuilder;
1512
+
1513
+ fn condition_metadata() -> Metadata {
1514
+ let mut metadata = MetadataBuilder::file(42);
1515
+ metadata
1516
+ .etag("etag")
1517
+ .version("version")
1518
+ .user_metadata([("owner".to_owned(), "opendal".to_owned())]);
1519
+ metadata.build()
1520
+ }
1521
+
1522
+ #[test]
1523
+ fn compact_operation_layouts() {
1524
+ assert_eq!(size_of::<OpRead>(), 16);
1525
+ assert_eq!(size_of::<OpStat>(), 16);
1526
+ assert_eq!(size_of::<OpWrite>(), 32);
1527
+ assert_eq!(size_of::<OpCompose>(), 32);
1528
+ assert_eq!(size_of::<OpDelete>(), 24);
1529
+ assert_eq!(size_of::<OpCopy>(), 64);
1530
+ assert_eq!(size_of::<OpList>(), 32);
1531
+ assert_eq!(size_of::<OpRestore>(), 24);
1532
+ }
1533
+
1534
+ #[test]
1535
+ fn read_options_roundtrip() {
1536
+ let modified = Timestamp::new(-1, -123).unwrap();
1537
+ let unmodified = Timestamp::new(2, 456).unwrap();
1538
+ let options = options::ReadOptions {
1539
+ version: Some("version".to_owned()),
1540
+ if_match: Some("etag".to_owned()),
1541
+ if_none_match: Some("other-etag".to_owned()),
1542
+ if_version_match: Some("version-match".to_owned()),
1543
+ if_version_not_match: Some("version-not-match".to_owned()),
1544
+ if_modified_since: Some(modified),
1545
+ if_unmodified_since: Some(unmodified),
1546
+ content_length_hint: Some(42),
1547
+ override_content_type: Some("text/plain".to_owned()),
1548
+ override_cache_control: Some("no-cache".to_owned()),
1549
+ override_content_disposition: Some("attachment".to_owned()),
1550
+ ..Default::default()
1551
+ };
1552
+ let (_, args, _) = options.into();
1553
+
1554
+ assert_eq!(args.version(), Some("version"));
1555
+ assert_eq!(args.if_match(), Some("etag"));
1556
+ assert_eq!(args.if_none_match(), Some("other-etag"));
1557
+ assert_eq!(args.if_version_match(), Some("version-match"));
1558
+ assert_eq!(args.if_version_not_match(), Some("version-not-match"));
1559
+ assert_eq!(args.if_modified_since(), Some(modified));
1560
+ assert_eq!(args.if_unmodified_since(), Some(unmodified));
1561
+ assert_eq!(args.content_length_hint(), Some(42));
1562
+ assert_eq!(args.override_content_type(), Some("text/plain"));
1563
+ assert_eq!(args.override_cache_control(), Some("no-cache"));
1564
+ assert_eq!(args.override_content_disposition(), Some("attachment"));
1565
+ assert!(args.is_conditional());
1566
+ }
1567
+
1568
+ #[test]
1569
+ fn write_options_preserve_owned_views() {
1570
+ let (args, _) = OpWrite::from_options(
1571
+ &Capability::default(),
1572
+ options::WriteOptions {
1573
+ append: true,
1574
+ concurrent: 4,
1575
+ content_type: Some("text/plain".to_owned()),
1576
+ content_disposition: Some("attachment".to_owned()),
1577
+ content_encoding: Some("gzip".to_owned()),
1578
+ cache_control: Some("no-cache".to_owned()),
1579
+ if_match: Some("etag".to_owned()),
1580
+ if_none_match: Some("other-etag".to_owned()),
1581
+ if_version_match: Some("version-match".to_owned()),
1582
+ if_version_not_match: Some("version-not-match".to_owned()),
1583
+ if_not_exists: true,
1584
+ user_metadata: Some(HashMap::from([("owner".to_owned(), "opendal".to_owned())])),
1585
+ ..Default::default()
1586
+ },
1587
+ )
1588
+ .unwrap();
1589
+
1590
+ assert!(args.append());
1591
+ assert_eq!(args.concurrent(), 4);
1592
+ assert_eq!(args.content_type(), Some("text/plain"));
1593
+ assert_eq!(args.content_disposition(), Some("attachment"));
1594
+ assert_eq!(args.content_encoding(), Some("gzip"));
1595
+ assert_eq!(args.cache_control(), Some("no-cache"));
1596
+ assert_eq!(args.if_match(), Some("etag"));
1597
+ assert_eq!(args.if_none_match(), Some("other-etag"));
1598
+ assert_eq!(args.if_version_match(), Some("version-match"));
1599
+ assert_eq!(args.if_version_not_match(), Some("version-not-match"));
1600
+ assert!(args.if_not_exists());
1601
+ assert_eq!(args.user_metadata().unwrap().get("owner"), Some("opendal"));
1602
+ assert!(args.is_conditional());
1603
+ }
1604
+
1605
+ #[test]
1606
+ fn compose_options_preserve_owned_views() {
1607
+ let args = OpCompose::from_options(
1608
+ &Capability::default(),
1609
+ options::ComposeOptions {
1610
+ concurrent: 4,
1611
+ content_type: Some("text/plain".to_owned()),
1612
+ content_disposition: Some("attachment".to_owned()),
1613
+ content_encoding: Some("gzip".to_owned()),
1614
+ cache_control: Some("no-cache".to_owned()),
1615
+ if_match: Some("etag".to_owned()),
1616
+ if_none_match: Some("other-etag".to_owned()),
1617
+ if_version_match: Some("version-match".to_owned()),
1618
+ if_version_not_match: Some("version-not-match".to_owned()),
1619
+ if_not_exists: true,
1620
+ user_metadata: Some(HashMap::from([("owner".to_owned(), "opendal".to_owned())])),
1621
+ ..Default::default()
1622
+ },
1623
+ )
1624
+ .unwrap();
1625
+
1626
+ assert_eq!(args.concurrent(), 4);
1627
+ assert_eq!(args.content_type(), Some("text/plain"));
1628
+ assert_eq!(args.content_disposition(), Some("attachment"));
1629
+ assert_eq!(args.content_encoding(), Some("gzip"));
1630
+ assert_eq!(args.cache_control(), Some("no-cache"));
1631
+ assert_eq!(args.if_match(), Some("etag"));
1632
+ assert_eq!(args.if_none_match(), Some("other-etag"));
1633
+ assert_eq!(args.if_version_match(), Some("version-match"));
1634
+ assert_eq!(args.if_version_not_match(), Some("version-not-match"));
1635
+ assert!(args.if_not_exists());
1636
+ assert_eq!(args.user_metadata().unwrap().get("owner"), Some("opendal"));
1637
+ assert!(args.is_conditional());
1638
+ }
1639
+
1640
+ #[test]
1641
+ fn options_lower_if_not_changed_before_freeze() {
1642
+ let condition = condition_metadata();
1643
+ let capability = Capability {
1644
+ write_with_if_match: true,
1645
+ write_with_if_version_match: true,
1646
+ delete_with_if_match: true,
1647
+ copy_with_if_match: true,
1648
+ ..Default::default()
1649
+ };
1650
+ let (write, _) = OpWrite::from_options(
1651
+ &capability,
1652
+ options::WriteOptions {
1653
+ if_not_changed: Some(condition.clone()),
1654
+ ..Default::default()
1655
+ },
1656
+ )
1657
+ .unwrap();
1658
+ assert_eq!(write.if_match(), None);
1659
+ assert_eq!(write.if_version_match(), Some("version"));
1660
+
1661
+ let delete = OpDelete::from_options(
1662
+ &capability,
1663
+ options::DeleteOptions {
1664
+ if_not_changed: Some(condition.clone()),
1665
+ ..Default::default()
1666
+ },
1667
+ )
1668
+ .unwrap();
1669
+ assert_eq!(delete.if_match(), Some("etag"));
1670
+ assert_eq!(delete.if_version_match(), None);
1671
+
1672
+ let copy = OpCopy::from_options(
1673
+ &capability,
1674
+ options::CopyOptions {
1675
+ if_not_changed: Some(condition.clone()),
1676
+ ..Default::default()
1677
+ },
1678
+ )
1679
+ .unwrap();
1680
+ assert_eq!(copy.if_match(), Some("etag"));
1681
+ assert_eq!(copy.if_version_match(), None);
1682
+
1683
+ let compose = OpCompose::from_options(
1684
+ &capability,
1685
+ options::ComposeOptions {
1686
+ if_not_changed: Some(condition.clone()),
1687
+ ..Default::default()
1688
+ },
1689
+ )
1690
+ .unwrap();
1691
+ assert_eq!(compose.if_match(), Some("etag"));
1692
+ assert_eq!(compose.if_version_match(), None);
1693
+
1694
+ let compose_source = OpRead::from_compose_source_options(
1695
+ &capability,
1696
+ options::ComposeSourceOptions {
1697
+ if_not_changed: Some(condition.clone()),
1698
+ ..Default::default()
1699
+ },
1700
+ )
1701
+ .unwrap();
1702
+ assert_eq!(compose_source.if_match(), Some("etag"));
1703
+ assert_eq!(compose_source.version(), None);
1704
+
1705
+ let compose_source = OpRead::from_compose_source_options(
1706
+ &Capability {
1707
+ compose_with_source_version: true,
1708
+ ..Default::default()
1709
+ },
1710
+ options::ComposeSourceOptions {
1711
+ if_not_changed: Some(condition),
1712
+ ..Default::default()
1713
+ },
1714
+ )
1715
+ .unwrap();
1716
+ assert_eq!(compose_source.if_match(), None);
1717
+ assert_eq!(compose_source.version(), Some("version"));
1718
+ }
1719
+
1720
+ #[test]
1721
+ fn delete_copy_list_and_restore_options_roundtrip() {
1722
+ let delete = OpDelete::from_options(
1723
+ &Capability::default(),
1724
+ options::DeleteOptions {
1725
+ version: Some("version".to_owned()),
1726
+ recursive: true,
1727
+ if_match: Some("etag".to_owned()),
1728
+ ..Default::default()
1729
+ },
1730
+ )
1731
+ .unwrap();
1732
+ assert_eq!(delete.version(), Some("version"));
1733
+ assert!(delete.recursive());
1734
+ assert_eq!(delete.if_match(), Some("etag"));
1735
+ assert!(delete.is_conditional());
1736
+
1737
+ let copy = OpCopy::from_options(
1738
+ &Capability::default(),
1739
+ options::CopyOptions {
1740
+ if_not_exists: true,
1741
+ if_version_match: Some("destination-version".to_owned()),
1742
+ source_version: Some("source-version".to_owned()),
1743
+ ..Default::default()
1744
+ },
1745
+ )
1746
+ .unwrap();
1747
+ assert!(copy.if_not_exists());
1748
+ assert_eq!(copy.if_version_match(), Some("destination-version"));
1749
+ assert_eq!(copy.source_version(), Some("source-version"));
1750
+ assert!(copy.is_conditional());
1751
+
1752
+ let list: OpList = options::ListOptions {
1753
+ limit: Some(100),
1754
+ start_after: Some("marker".to_owned()),
1755
+ recursive: true,
1756
+ versions: true,
1757
+ deleted: true,
1758
+ }
1759
+ .into();
1760
+ assert_eq!(list.limit(), Some(100));
1761
+ assert_eq!(list.start_after(), Some("marker"));
1762
+ assert!(list.recursive());
1763
+ assert!(list.versions());
1764
+ assert!(list.deleted());
1765
+
1766
+ let restore: OpRestore = options::RestoreOptions {
1767
+ version: Some("version".to_owned()),
1768
+ if_not_exists: true,
1769
+ }
1770
+ .into();
1771
+ assert_eq!(restore.version(), Some("version"));
1772
+ assert!(restore.if_not_exists());
1773
+ assert!(restore.is_conditional());
1774
+ }
1775
+ }