#amazon-s3 #path #s3-path

s3-path

Describe paths inside an S3 bucket like working with std's Path and PathBuf

4 releases

new 0.1.3 May 21, 2025
0.1.2 May 21, 2025
0.0.2 May 20, 2025

#1048 in Filesystem

Download history 86/week @ 2025-05-14

86 downloads per month

MIT/Apache

25KB
543 lines

s3-path

Construct safe S3 keys (informally named paths in this library).

This library only allows the following characters to be used in path components:

  • [a..z], [A..Z], [0..9], -, _, .

The following path components are explicitly forbidden to avoid any path traversal when the S3 key is used as a filesystem path:

  • .
  • ..

Usage

fn owned() {
    let mut path = S3PathBuf::new();
    path.join("foo").unwrap();
    path.join("bar").unwrap();
    assert_that(path).has_display_value("foo/bar");

    let path = S3PathBuf::try_from(["foo/bar", "baz"]).unwrap();
    assert_that(path).has_display_value("foobar/baz");
    
    let path = S3PathBuf::try_from_str("foo/bar").unwrap();
    assert_that(path).has_display_value("foo/bar");
}

fn borrowed() {
    let path = S3Path::new([Cow::Borrowed("foo"), Cow::Borrowed("bar")]).unwrap();
    assert_that(path).has_display_value("foo/bar");
}

TODO

  • Check for maximum key limit? Should be 1024 bytes (of UTF-8) on Amazon S3. What about MinIO, Ceph, ...?

No runtime deps