in sdk/core/azure_core/src/http/request/options/content_range.rs [45:121]
fn from_str(s: &str) -> crate::Result<ContentRange> {
let remaining = s.strip_prefix(PREFIX).ok_or_else(|| {
Error::with_message(ErrorKind::Other, || {
format!(
"expected token \"{PREFIX}\" not found when parsing ContentRange from \"{s}\""
)
})
})?;
// when requesting zero byte files from azurite, it can generate invalid content-range
// headers. See Azure/Azurite#1682 for more information.
if cfg!(feature = "azurite_workaround") && remaining == "0--1/0" {
return Ok(ContentRange {
start: 0,
end: 0,
total_length: 0,
});
}
let mut split_at_dash = remaining.split('-');
let start = split_at_dash
.next()
.ok_or_else(|| {
Error::with_message(ErrorKind::Other, || {
format!(
"expected token \"{}\" not found when parsing ContentRange from \"{}\"",
"-", s
)
})
})?
.parse()
.map_kind(ErrorKind::DataConversion)?;
let mut split_at_slash = split_at_dash
.next()
.ok_or_else(|| {
Error::with_message(ErrorKind::Other, || {
format!(
"expected token \"{}\" not found when parsing ContentRange from \"{}\"",
"-", s
)
})
})?
.split('/');
let end = split_at_slash
.next()
.ok_or_else(|| {
Error::with_message(ErrorKind::Other, || {
format!(
"expected token \"{}\" not found when parsing ContentRange from \"{}\"",
"/", s
)
})
})?
.parse()
.map_kind(ErrorKind::DataConversion)?;
let total_length = split_at_slash
.next()
.ok_or_else(|| {
Error::with_message(ErrorKind::Other, || {
format!(
"expected token \"{}\" not found when parsing ContentRange from \"{}\"",
"/", s
)
})
})?
.parse()
.map_kind(ErrorKind::DataConversion)?;
Ok(ContentRange {
start,
end,
total_length,
})
}