20
20
#include " eckit/io/s3/S3Exception.h"
21
21
#include " eckit/io/s3/S3Handle.h"
22
22
#include " eckit/io/s3/S3Name.h"
23
+ #include " eckit/io/s3/S3ObjectPath.h"
23
24
#include " eckit/log/CodeLocation.h"
24
25
#include " eckit/net/Endpoint.h"
25
26
@@ -31,57 +32,60 @@ namespace eckit {
31
32
32
33
// ----------------------------------------------------------------------------------------------------------------------
33
34
34
- S3ObjectName::S3ObjectName (const URI& uri) : S3Name(uri) {
35
- const auto pairs = parse (uri.name ());
36
- if (pairs.size () != 2 ) { throw S3SeriousBug (" Could not parse bucket and object names!" , Here ()); }
37
- bucket_ = pairs[0 ];
38
- object_ = pairs[1 ];
35
+ auto S3ObjectName::parse (const std::string& name) -> S3ObjectPath {
36
+ const auto parsed = S3Name::parse (name);
37
+ if (parsed.size () != 2 ) { throw S3SeriousBug (" Could not parse bucket/object from name: " + name, Here ()); }
38
+ return {parsed[0 ], parsed[1 ]};
39
39
}
40
40
41
- S3ObjectName::S3ObjectName (const net::Endpoint& endpoint, std::string bucket, std::string object)
42
- : S3Name(endpoint), bucket_ {std::move (bucket)}, object_ {std::move (object)} { }
41
+ // ----------------------------------------------------------------------------------------------------------------------
42
+
43
+ S3ObjectName::S3ObjectName (const net::Endpoint& endpoint, S3ObjectPath path)
44
+ : S3Name(endpoint), path_ {std::move (path)} { }
45
+
46
+ S3ObjectName::S3ObjectName (const URI& uri) : S3Name(uri), path_ {parse (uri.name ())} { }
43
47
44
48
// ----------------------------------------------------------------------------------------------------------------------
45
49
46
50
void S3ObjectName::print (std::ostream& out) const {
47
- out << " S3ObjectName[object =" << object_ << " ,bucket= " << bucket_ ;
51
+ out << " S3ObjectName[path =" << path_ ;
48
52
S3Name::print (out);
49
53
}
50
54
51
55
// ----------------------------------------------------------------------------------------------------------------------
52
56
53
57
auto S3ObjectName::uri () const -> URI {
54
58
auto uri = S3Name::uri ();
55
- uri.path (" / " + bucket_ + " / " + object_ );
59
+ uri.path (path_ );
56
60
return uri;
57
61
}
58
62
59
63
auto S3ObjectName::asString () const -> std::string {
60
- return S3Name::asString () + " / " + bucket_ + " / " + object_ ;
64
+ return S3Name::asString () + ' / ' + path_. asString () ;
61
65
}
62
66
63
67
auto S3ObjectName::size () const -> long long {
64
- return client ().objectSize (bucket_, object_ );
68
+ return client ().objectSize (path_ );
65
69
}
66
70
67
71
auto S3ObjectName::exists () const -> bool {
68
- return client ().objectExists (bucket_, object_ );
72
+ return client ().objectExists (path_ );
69
73
}
70
74
71
75
auto S3ObjectName::bucketExists () const -> bool {
72
- return client ().bucketExists (bucket_ );
76
+ return client ().bucketExists (path_. bucket );
73
77
}
74
78
75
79
void S3ObjectName::remove () {
76
- client ().deleteObject (bucket_, object_ );
80
+ client ().deleteObject (path_ );
77
81
}
78
82
79
83
auto S3ObjectName::put (const void * buffer, const long length) const -> long long {
80
- return client ().putObject (bucket_, object_ , buffer, length);
84
+ return client ().putObject (path_ , buffer, length);
81
85
}
82
86
83
87
auto S3ObjectName::get (void * buffer, const long offset, const long length) const -> long long {
84
- return client ().getObject (bucket_, object_ , buffer, offset, length);
88
+ return client ().getObject (path_ , buffer, offset, length);
85
89
}
86
90
87
91
auto S3ObjectName::dataHandle () -> DataHandle* {
0 commit comments