Skip to content

Commit 0f794d7

Browse files
committed
chore: use bufreader to improve snapshot file serialization
1 parent 33637d4 commit 0f794d7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

soroban-ledger-snapshot/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde_with::serde_as;
22
use std::{
33
fs::{create_dir_all, File},
4-
io::{self, Read, Write},
4+
io::{self, BufReader, Read, Write},
55
path::Path,
66
rc::Rc,
77
};
@@ -214,7 +214,8 @@ impl LedgerSnapshot {
214214

215215
/// Read in a [`LedgerSnapshot`] from a file.
216216
pub fn read_file(p: impl AsRef<Path>) -> Result<LedgerSnapshot, Error> {
217-
Self::read(File::open(p)?)
217+
let reader = BufReader::new(File::open(p)?);
218+
Self::read(reader)
218219
}
219220

220221
/// Write a [`LedgerSnapshot`] to a writer.

soroban-sdk/src/testutils.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ impl Snapshot {
7272

7373
// Read in a [`Snapshot`] from a file.
7474
pub fn read_file(p: impl AsRef<std::path::Path>) -> Result<Snapshot, std::io::Error> {
75-
Self::read(std::fs::File::open(p)?)
75+
let reader = std::io::BufReader::new(std::fs::File::open(p)?);
76+
Self::read(reader)
7677
}
7778

7879
// Write a [`Snapshot`] to a writer.
@@ -104,7 +105,8 @@ impl EventsSnapshot {
104105

105106
// Read in a [`EventsSnapshot`] from a file.
106107
pub fn read_file(p: impl AsRef<std::path::Path>) -> Result<EventsSnapshot, std::io::Error> {
107-
Self::read(std::fs::File::open(p)?)
108+
let reader = std::io::BufReader::new(std::fs::File::open(p)?);
109+
Self::read(reader)
108110
}
109111

110112
// Write a [`EventsSnapshot`] to a writer.
@@ -154,7 +156,8 @@ impl AuthSnapshot {
154156

155157
// Read in a [`AuthSnapshot`] from a file.
156158
pub fn read_file(p: impl AsRef<std::path::Path>) -> Result<AuthSnapshot, std::io::Error> {
157-
Self::read(std::fs::File::open(p)?)
159+
let reader = std::io::BufReader::new(std::fs::File::open(p)?);
160+
Self::read(reader)
158161
}
159162

160163
// Write a [`AuthSnapshot`] to a writer.
@@ -200,7 +203,8 @@ impl Generators {
200203

201204
// Read in a [`Generators`] from a file.
202205
pub fn read_file(p: impl AsRef<std::path::Path>) -> Result<Generators, std::io::Error> {
203-
Self::read(std::fs::File::open(p)?)
206+
let reader = std::io::BufReader::new(std::fs::File::open(p)?);
207+
Self::read(reader)
204208
}
205209

206210
// Write a [`Generators`] to a writer.

0 commit comments

Comments
 (0)