1#[derive(Debug, Clone)]
3pub struct BlobConfig {
4 pub max_blob_bytes: u64,
6
7 pub multipart_threshold_bytes: u64,
9
10 pub upload_rules: UploadRules,
12
13 pub require_range_support: bool,
17
18 pub checksum_alg: Option<String>,
20}
21
22impl Default for BlobConfig {
23 fn default() -> Self {
24 Self {
25 max_blob_bytes: 5 * 1024 * 1024 * 1024, multipart_threshold_bytes: 16 * 1024 * 1024, upload_rules: UploadRules::default(),
28 require_range_support: false,
29 checksum_alg: None,
30 }
31 }
32}
33
34#[derive(Debug, Clone)]
36pub struct UploadRules {
37 pub part_size: u64,
39
40 pub max_parts: u32,
42
43 pub require_fixed_part_size: bool,
45
46 pub allow_out_of_order: bool,
48}
49
50impl Default for UploadRules {
51 fn default() -> Self {
52 Self {
53 part_size: 8 * 1024 * 1024, max_parts: 10_000,
55 require_fixed_part_size: true,
56 allow_out_of_order: true,
57 }
58 }
59}
60
61impl BlobConfig {
62 pub fn new() -> Self {
64 Self::default()
65 }
66
67 pub fn with_max_blob_bytes(mut self, bytes: u64) -> Self {
69 self.max_blob_bytes = bytes;
70 self
71 }
72
73 pub fn with_multipart_threshold(mut self, bytes: u64) -> Self {
75 self.multipart_threshold_bytes = bytes;
76 self
77 }
78
79 pub fn with_upload_rules(mut self, rules: UploadRules) -> Self {
81 self.upload_rules = rules;
82 self
83 }
84
85 pub fn require_range_support(mut self) -> Self {
87 self.require_range_support = true;
88 self
89 }
90
91 pub fn with_checksum<S: Into<String>>(mut self, algorithm: S) -> Self {
93 self.checksum_alg = Some(algorithm.into());
94 self
95 }
96}
97
98impl UploadRules {
99 pub fn new() -> Self {
101 Self::default()
102 }
103
104 pub fn with_part_size(mut self, bytes: u64) -> Self {
106 self.part_size = bytes;
107 self
108 }
109
110 pub fn with_max_parts(mut self, max: u32) -> Self {
112 self.max_parts = max;
113 self
114 }
115
116 pub fn allow_variable_part_sizes(mut self) -> Self {
118 self.require_fixed_part_size = false;
119 self
120 }
121
122 pub fn require_ordered_parts(mut self) -> Self {
124 self.allow_out_of_order = false;
125 self
126 }
127}