Skip to content

Commit 73dcc09

Browse files
committed
RopeReader never fails
1 parent 48ac8ce commit 73dcc09

File tree

9 files changed

+18
-18
lines changed

9 files changed

+18
-18
lines changed

crates/next-core/src/next_app/metadata/image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async fn hash_file_content(path: Vc<FileSystemPath>) -> Result<u64> {
2929

3030
Ok(match &*original_file_content {
3131
FileContent::Content(content) => {
32-
let content = content.content().to_bytes()?;
32+
let content = content.content().to_bytes();
3333
hash_xxh3_hash64(&*content)
3434
}
3535
FileContent::NotFound => {

crates/next-core/src/next_app/metadata/route.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async fn get_base64_file_content(path: Vc<FileSystemPath>) -> Result<String> {
117117

118118
Ok(match &*original_file_content {
119119
FileContent::Content(content) => {
120-
let content = content.content().to_bytes()?;
120+
let content = content.content().to_bytes();
121121
Base64Display::new(&content, &STANDARD).to_string()
122122
}
123123
FileContent::NotFound => {

crates/next-core/src/next_font/local/font_fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async fn get_font_adjustment(
108108
FileContent::Content(file) => file.content(),
109109
};
110110

111-
let font_file_binary = font_file_rope.to_bytes()?;
111+
let font_file_binary = font_file_rope.to_bytes();
112112
let scope = allsorts::binary::read::ReadScope::new(&font_file_binary);
113113
let mut font = Font::new(scope.read::<FontData>()?.table_provider(0)?)?.context(format!(
114114
"Unable to read font metrics from font file at {}",

crates/next-core/src/next_shared/transforms/swc_ecma_transform_plugins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub async fn get_swc_ecma_transform_rule_impl(
101101
};
102102

103103
Ok(Some((
104-
SwcPluginModule::new(name, file.content().to_bytes()?.to_vec()).resolved_cell(),
104+
SwcPluginModule::new(name, file.content().to_bytes().to_vec()).resolved_cell(),
105105
config.clone(),
106106
)))
107107
})

turbopack/crates/turbo-tasks-fs/src/rope.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl Rope {
114114
}
115115

116116
/// Returns a slice of all bytes
117-
pub fn to_bytes(&self) -> Result<Cow<'_, [u8]>> {
117+
pub fn to_bytes(&self) -> Cow<'_, [u8]> {
118118
self.data.to_bytes(self.length)
119119
}
120120
}
@@ -362,8 +362,7 @@ impl Serialize for Rope {
362362
/// deserialization won't deduplicate and share the Arcs (being the only
363363
/// possible owner of a individual "shared" data doesn't make sense).
364364
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
365-
use serde::ser::Error;
366-
let bytes = self.to_bytes().map_err(Error::custom)?;
365+
let bytes = self.to_bytes();
367366
match bytes {
368367
Cow::Borrowed(b) => serde_bytes::Bytes::new(b).serialize(serializer),
369368
Cow::Owned(b) => ByteBuf::from(b).serialize(serializer),
@@ -523,16 +522,17 @@ impl InnerRope {
523522
}
524523

525524
/// Returns a slice of all bytes.
526-
fn to_bytes(&self, len: usize) -> Result<Cow<'_, [u8]>> {
525+
fn to_bytes(&self, len: usize) -> Cow<'_, [u8]> {
527526
match &self[..] {
528-
[] => Ok(Cow::Borrowed(EMPTY_BUF)),
527+
[] => Cow::Borrowed(EMPTY_BUF),
529528
[Shared(inner)] => inner.to_bytes(len),
530-
[Local(bytes)] => Ok(Cow::Borrowed(bytes)),
529+
[Local(bytes)] => Cow::Borrowed(bytes),
531530
_ => {
532531
let mut read = RopeReader::new(self, 0);
533532
let mut buf = Vec::with_capacity(len);
534-
read.read_to_end(&mut buf)?;
535-
Ok(Cow::Owned(buf))
533+
read.read_to_end(&mut buf)
534+
.expect("rope reader should not fail");
535+
buf.into()
536536
}
537537
}
538538
}
@@ -1045,7 +1045,7 @@ mod test {
10451045
#[test]
10461046
fn test_to_bytes() -> Result<()> {
10471047
let rope = Rope::from("abc");
1048-
assert_eq!(rope.to_bytes()?, Cow::Borrowed::<[u8]>(&[0x61, 0x62, 0x63]));
1048+
assert_eq!(rope.to_bytes(), Cow::Borrowed::<[u8]>(&[0x61, 0x62, 0x63]));
10491049
Ok(())
10501050
}
10511051
}

turbopack/crates/turbopack-image/src/process/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub async fn get_meta_data(
347347
let FileContent::Content(content) = &*content.await? else {
348348
bail!("Input image not found");
349349
};
350-
let bytes = content.content().to_bytes()?;
350+
let bytes = content.content().to_bytes();
351351
let path_resolved = ident.path().to_resolved().await?;
352352
let path = path_resolved.await?;
353353
let extension = path.extension_ref();
@@ -430,7 +430,7 @@ pub async fn optimize(
430430
let FileContent::Content(content) = &*content.await? else {
431431
return Ok(FileContent::NotFound.cell());
432432
};
433-
let bytes = content.content().to_bytes()?;
433+
let bytes = content.content().to_bytes();
434434
let path = ident.path().to_resolved().await?;
435435

436436
let Some((image, format)) = load_image(path, &bytes, ident.path().await?.extension_ref())

turbopack/crates/turbopack-node/src/transforms/webpack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl WebpackLoadersProcessedAsset {
230230
"binary".to_string(),
231231
JsonValue::from(
232232
base64::engine::general_purpose::STANDARD
233-
.encode(file_content.content().to_bytes().unwrap()),
233+
.encode(file_content.content().to_bytes()),
234234
),
235235
)))),
236236
};

turbopack/crates/turbopack-wasm/src/analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) async fn analyze(source: Vc<WebAssemblySource>) -> Result<Vc<WebAssem
2929
return Ok(analysis.cell());
3030
};
3131

32-
let mut bytes = &*file.content().to_bytes()?;
32+
let mut bytes = &*file.content().to_bytes();
3333

3434
let mut parser = Parser::new(0);
3535
loop {

turbopack/crates/turbopack-wasm/src/source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl Asset for WebAssemblySource {
7676
return Ok(AssetContent::file(FileContent::NotFound.cell()));
7777
};
7878

79-
let bytes = file.content().to_bytes()?;
79+
let bytes = file.content().to_bytes();
8080
let parsed = wat::parse_bytes(&bytes)?;
8181

8282
Ok(AssetContent::file(File::from(&*parsed).into()))

0 commit comments

Comments
 (0)