2020#include " eckit/io/s3/S3Exception.h"
2121#include " eckit/io/s3/S3Handle.h"
2222#include " eckit/io/s3/S3Name.h"
23+ #include " eckit/io/s3/S3ObjectPath.h"
2324#include " eckit/log/CodeLocation.h"
2425#include " eckit/net/Endpoint.h"
2526
@@ -31,57 +32,60 @@ namespace eckit {
3132
3233// ----------------------------------------------------------------------------------------------------------------------
3334
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 ]};
3939}
4040
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 ())} { }
4347
4448// ----------------------------------------------------------------------------------------------------------------------
4549
4650void S3ObjectName::print (std::ostream& out) const {
47- out << " S3ObjectName[object =" << object_ << " ,bucket= " << bucket_ ;
51+ out << " S3ObjectName[path =" << path_ ;
4852 S3Name::print (out);
4953}
5054
5155// ----------------------------------------------------------------------------------------------------------------------
5256
5357auto S3ObjectName::uri () const -> URI {
5458 auto uri = S3Name::uri ();
55- uri.path (" / " + bucket_ + " / " + object_ );
59+ uri.path (path_ );
5660 return uri;
5761}
5862
5963auto S3ObjectName::asString () const -> std::string {
60- return S3Name::asString () + " / " + bucket_ + " / " + object_ ;
64+ return S3Name::asString () + ' / ' + path_. asString () ;
6165}
6266
6367auto S3ObjectName::size () const -> long long {
64- return client ().objectSize (bucket_, object_ );
68+ return client ().objectSize (path_ );
6569}
6670
6771auto S3ObjectName::exists () const -> bool {
68- return client ().objectExists (bucket_, object_ );
72+ return client ().objectExists (path_ );
6973}
7074
7175auto S3ObjectName::bucketExists () const -> bool {
72- return client ().bucketExists (bucket_ );
76+ return client ().bucketExists (path_. bucket );
7377}
7478
7579void S3ObjectName::remove () {
76- client ().deleteObject (bucket_, object_ );
80+ client ().deleteObject (path_ );
7781}
7882
7983auto 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);
8185}
8286
8387auto 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);
8589}
8690
8791auto S3ObjectName::dataHandle () -> DataHandle* {
0 commit comments