Buffered read/write

This commit is contained in:
Aditya Kulkarni 2019-09-06 20:52:36 -07:00
parent 8ff6d15e32
commit 4dbba14f4e

View File

@ -4,6 +4,7 @@ use std::path::Path;
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::io::{BufReader, BufWriter};
use std::sync::Arc;
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
@ -72,7 +73,7 @@ impl LightClient {
print!("Reading wallet...");
io::stdout().flush().ok().expect("Could not flush stdout");
let mut file_buffer = match File::open("wallet.dat") {
Ok(f) => f,
Ok(f) => BufReader::new(f),
Err(e) => {
println!("[Error: {}]", e.description());
return;
@ -87,7 +88,9 @@ impl LightClient {
pub fn do_save(&self) {
print!("Saving wallet...");
io::stdout().flush().ok().expect("Could not flush stdout");
let mut file_buffer = File::create("wallet.dat").unwrap();
let mut file_buffer = BufWriter::with_capacity(
1_000_000, // 1 MB write buffer
File::create("wallet.dat").unwrap());
self.wallet.write(&mut file_buffer).unwrap();
println!("[OK]");