Skip to main content

rustfs_storage_api/
multipart.rs

1// Copyright 2024 RustFS Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::collections::HashMap;
16use time::OffsetDateTime;
17
18#[derive(Debug, Default, Clone)]
19pub struct MultipartUploadResult {
20    pub upload_id: String,
21    pub checksum_algo: Option<String>,
22    pub checksum_type: Option<String>,
23}
24
25#[derive(Debug, Default, Clone)]
26pub struct PartInfo {
27    pub part_num: usize,
28    pub last_mod: Option<OffsetDateTime>,
29    pub size: usize,
30    pub etag: Option<String>,
31    pub actual_size: i64,
32}
33
34#[derive(Debug, Clone, Default)]
35pub struct MultipartInfo {
36    pub bucket: String,
37    pub object: String,
38    pub upload_id: String,
39    pub initiated: Option<OffsetDateTime>,
40    pub user_defined: HashMap<String, String>,
41}
42
43#[derive(Debug, Clone, Default)]
44pub struct ListMultipartsInfo {
45    pub key_marker: Option<String>,
46    pub upload_id_marker: Option<String>,
47    pub next_key_marker: Option<String>,
48    pub next_upload_id_marker: Option<String>,
49    pub max_uploads: usize,
50    pub is_truncated: bool,
51    pub uploads: Vec<MultipartInfo>,
52    pub prefix: String,
53    pub delimiter: Option<String>,
54    pub common_prefixes: Vec<String>,
55}
56
57#[derive(Debug, Clone, Default)]
58pub struct ListPartsInfo {
59    pub bucket: String,
60    pub object: String,
61    pub upload_id: String,
62    pub storage_class: String,
63    pub part_number_marker: usize,
64    pub next_part_number_marker: usize,
65    pub max_parts: usize,
66    pub is_truncated: bool,
67    pub parts: Vec<PartInfo>,
68    pub user_defined: HashMap<String, String>,
69    pub checksum_algorithm: String,
70    pub checksum_type: String,
71}
72
73#[derive(Debug, Clone, Default)]
74pub struct CompletePart {
75    pub part_num: usize,
76    pub etag: Option<String>,
77    pub checksum_crc32: Option<String>,
78    pub checksum_crc32c: Option<String>,
79    pub checksum_sha1: Option<String>,
80    pub checksum_sha256: Option<String>,
81    pub checksum_crc64nvme: Option<String>,
82}
83
84#[cfg(test)]
85mod tests {
86    use super::*;
87
88    #[test]
89    fn complete_part_defaults_preserve_empty_checksums() {
90        let part = CompletePart::default();
91
92        assert_eq!(part.part_num, 0);
93        assert!(part.etag.is_none());
94        assert!(part.checksum_crc32.is_none());
95        assert!(part.checksum_crc32c.is_none());
96        assert!(part.checksum_sha1.is_none());
97        assert!(part.checksum_sha256.is_none());
98        assert!(part.checksum_crc64nvme.is_none());
99    }
100}