feat(ecstore): LocalDisk writes file by spawn_blocking

This commit is contained in:
Nugine
2025-06-15 21:01:38 +08:00
parent 2f3dbac59b
commit 82cc1402c4
+15 -6
View File
@@ -671,12 +671,21 @@ impl LocalDisk {
}
};
let data: &[u8] = match &data {
InternalBuf::Ref(buf) => buf,
InternalBuf::Owned(buf) => buf.as_ref(),
};
f.write_all(data).await.map_err(to_file_error)?;
match data {
InternalBuf::Ref(buf) => {
f.write_all(buf).await.map_err(to_file_error)?;
}
InternalBuf::Owned(buf) => {
// Reduce one copy by using the owned buffer directly.
// It may be more efficient for larger writes.
let mut f = f.into_std().await;
let task = tokio::task::spawn_blocking(move || {
use std::io::Write as _;
f.write_all(buf.as_ref()).map_err(to_file_error)
});
task.await??;
}
}
Ok(())
}