Skip to content

Commit 90ca846

Browse files
authored
feat(rust-client): Add a util to guess MIME type (#200)
1 parent b5d40b2 commit 90ca846

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ publish = true
1414
async-compression = { version = "0.4.27", features = ["tokio", "zstd"] }
1515
bytes = { workspace = true }
1616
futures-util = { workspace = true }
17+
infer = { version = "0.19.0", default-features = false }
1718
objectstore-types = { workspace = true }
1819
reqwest = { workspace = true, features = ["json", "stream"] }
1920
sentry-core = { version = ">=0.41", features = ["client"] }

clients/rust/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod delete;
77
mod error;
88
mod get;
99
mod put;
10+
pub mod utils;
1011

1112
pub use objectstore_types::{Compression, ExpirationPolicy};
1213

clients/rust/src/put.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ impl PutBuilder {
109109
}
110110

111111
/// Sets the content type of the object to be uploaded.
112+
///
113+
/// You can use the utility function [`crate::utils::guess_mime_type`] to attempt to guess a
114+
/// `content_type` based on magic bytes.
112115
pub fn content_type(mut self, content_type: impl Into<Cow<'static, str>>) -> Self {
113116
self.metadata.content_type = content_type.into();
114117
self

clients/rust/src/utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Utility functions that might be useful when working with Objectstore.
2+
3+
/// Attempts to guess the MIME type from the given contents.
4+
pub fn guess_mime_type<T: AsRef<[u8]>>(contents: T) -> Option<&'static str> {
5+
infer::get(contents.as_ref()).map(|kind| kind.mime_type())
6+
}

0 commit comments

Comments
 (0)