Skip to content

Commit 3b8da77

Browse files
committed
use BufReader/BufWriter
1 parent 47e324d commit 3b8da77

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

encoderfile-runtime/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clap::Parser;
22
use parking_lot::Mutex;
33
use std::{
44
fs::File,
5-
io::{Read, Seek},
5+
io::{BufReader, Read, Seek},
66
sync::Arc,
77
};
88

@@ -22,7 +22,8 @@ use encoderfile_core::{
2222
async fn main() -> Result<()> {
2323
// open current executable
2424
let path = std::env::current_exe()?;
25-
let mut file = File::open(path)?;
25+
let file = File::open(path)?;
26+
let mut file = BufReader::new(file);
2627
// load encoderfile
2728
let mut loader = load_assets(&mut file)?;
2829

@@ -73,7 +74,7 @@ async fn entrypoint<'a, R: Read + Seek>(loader: &mut EncoderfileLoader<'a, R>) -
7374
}
7475
}
7576

76-
fn load_assets<'a>(file: &'a mut File) -> Result<EncoderfileLoader<'a, std::fs::File>> {
77+
fn load_assets<'a, R: Read + Seek>(file: &'a mut R) -> Result<EncoderfileLoader<'a, R>> {
7778
let encoderfile = EncoderfileCodec::read(file)?;
7879
let loader = EncoderfileLoader::new(encoderfile, file);
7980

encoderfile/src/cli.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ use encoderfile_core::{
77
},
88
generated::manifest::Backend,
99
};
10-
use std::{borrow::Cow, fs::File, io::Seek, path::PathBuf};
10+
use std::{
11+
borrow::Cow,
12+
fs::File,
13+
io::{BufWriter, Seek, Write},
14+
path::PathBuf,
15+
};
1116

1217
use clap_derive::{Args, Parser, Subcommand};
1318

@@ -120,7 +125,8 @@ impl BuildArgs {
120125
};
121126

122127
// initialize final binary
123-
let mut out = File::create(config.encoderfile.output_path())?;
128+
let out = File::create(config.encoderfile.output_path())?;
129+
let mut out = BufWriter::new(out);
124130
let mut base = File::open(base_path)?;
125131

126132
// copy base binary to out
@@ -145,6 +151,8 @@ impl BuildArgs {
145151
&mut out,
146152
)?;
147153

154+
out.flush()?;
155+
148156
Ok(())
149157
}
150158
}

0 commit comments

Comments
 (0)