Skip to content

Commit

Permalink
s3 fs (#28)
Browse files Browse the repository at this point in the history
* feat: support s3 write

* feat: support native s3 fs

* pub tokio http client

* feat: support s3 list and remove
  • Loading branch information
ethe authored Sep 29, 2024
1 parent 317b1b0 commit a7b9b00
Show file tree
Hide file tree
Showing 14 changed files with 738 additions and 181 deletions.
18 changes: 16 additions & 2 deletions fusio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ version = "0.1.0"

[features]
aws = [
"base64",
"bytes",
"chrono",
"chrono?/serde",
"fs",
"http",
"quick-xml",
"ring",
"serde",
"serde_json",
"serde_urlencoded",
]
bytes = ["dep:bytes"]
completion-based = []
default = ["dyn", "fs"]
dyn = []
fs = ["tokio?/rt"]
h2 = ["dep:h2"]
http = [
"async-stream",
"bytes",
"dep:http",
"http-body",
"http-body-util",
Expand All @@ -40,7 +44,9 @@ tokio-uring = ["async-stream", "completion-based", "dep:tokio-uring", "no-send"]

[dependencies]
async-stream = { version = "0.3", optional = true }
base64 = { version = "0.22", optional = true }
bytes = { workspace = true, optional = true }
cfg-if = "1.0.0"
chrono = { version = "0.4", optional = true, default-features = false, features = [
"now",
"std",
Expand All @@ -62,12 +68,19 @@ object_store = { version = "0.11", optional = true, default-features = false, fe
"aws",
] }
percent-encoding = { version = "2" }
reqwest = { version = "0.12.7", optional = true, features = ["stream"] }
quick-xml = { version = "0.36", features = [
"overlapped-lists",
"serialize",
], optional = true }
reqwest = { git = "https://github.com/seanmonstar/reqwest.git", optional = true, features = [
"stream",
] }
ring = { version = "0.17", optional = true, default-features = false, features = [
"std",
] }
serde = { version = "1", optional = true, features = ["derive"] }
serde_json = { version = "1", optional = true }
serde_urlencoded = { version = "0.7", optional = true }
thiserror = "1"
tokio = { version = "1", optional = true, default-features = false, features = [
"fs",
Expand All @@ -79,6 +92,7 @@ url = { version = "2" }
tokio-uring = { version = "0.5", default-features = false, optional = true }

[dev-dependencies]
futures-util = { version = "0.3" }
hyper = { version = "1", features = ["full"] }
hyper-util = { version = "0.1", features = ["full"] }
monoio = { version = "0.2" }
Expand Down
4 changes: 4 additions & 0 deletions fusio/src/buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ pub trait IoBufMut: IoBuf {
unsafe { std::slice::from_raw_parts_mut(self.as_mut_ptr(), self.bytes_init()) }
}

/// # Safety
/// The buffer must be recovered from the same type of buffer before it drops.
unsafe fn to_buf_mut_nocopy(self) -> BufMut;

/// # Safety
/// The buffer must be recovered from the same type.
unsafe fn recover_from_buf_mut(buf: BufMut) -> Self;
}

Expand Down
13 changes: 11 additions & 2 deletions fusio/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use thiserror::Error;

#[derive(Debug, Error)]
#[error(transparent)]
#[non_exhaustive]
pub enum Error {
Io(#[from] io::Error),
#[cfg(feature = "http")]
Expand All @@ -14,8 +15,16 @@ pub enum Error {
#[error("unsupported operation")]
Unsupported,
#[error(transparent)]
Other(BoxError),
Other(#[from] BoxedError),
#[error("invalid url: {0}")]
InvalidUrl(BoxedError),
#[cfg(feature = "http")]
#[error("http request failed, status: {status_code}, body: {body}")]
HttpNotSuccess {
status_code: http::StatusCode,
body: String,
},
}

#[allow(unused)]
pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
pub type BoxedError = Box<dyn std::error::Error + Send + Sync + 'static>;
1 change: 1 addition & 0 deletions fusio/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub use options::*;

use crate::{path::Path, Error, MaybeSend, MaybeSync, Read, Seek, Write};

#[derive(Debug)]
pub struct FileMeta {
pub path: Path,
pub size: u64,
Expand Down
9 changes: 9 additions & 0 deletions fusio/src/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ pub use tokio::fs::*;
#[cfg(all(feature = "tokio-uring", target_os = "linux", feature = "fs"))]
#[allow(unused)]
pub use tokio_uring::fs::*;

#[cfg(feature = "fs")]
cfg_if::cfg_if! {
if #[cfg(feature = "tokio")] {
pub type LocalFs = TokioFs;
} else if #[cfg(feature = "monoio")] {
pub type LocalFs = MonoIoFs;
}
}
Loading

0 comments on commit a7b9b00

Please sign in to comment.