Refactor to use a const.
This commit is contained in:
parent
da058d0e86
commit
d6701065ea
@ -398,7 +398,9 @@ fn execute_import(conf: Configuration) {
|
|||||||
Box::new(::std::io::stdin())
|
Box::new(::std::io::stdin())
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut first_bytes: Bytes = vec![0; 8];
|
const READAHEAD_BYTES: usize = 8;
|
||||||
|
|
||||||
|
let mut first_bytes: Bytes = vec![0; READAHEAD_BYTES];
|
||||||
let mut first_read = 0;
|
let mut first_read = 0;
|
||||||
|
|
||||||
let format = match conf.args.flag_format {
|
let format = match conf.args.flag_format {
|
||||||
@ -438,13 +440,13 @@ fn execute_import(conf: Configuration) {
|
|||||||
match format {
|
match format {
|
||||||
DataFormat::Binary => {
|
DataFormat::Binary => {
|
||||||
loop {
|
loop {
|
||||||
let mut bytes: Bytes = if first_read > 0 {first_bytes.clone()} else {vec![0; 8]};
|
let mut bytes: Bytes = if first_read > 0 {first_bytes.clone()} else {vec![0; READAHEAD_BYTES]};
|
||||||
let n = if first_read > 0 {first_read} else {instream.read(&mut(bytes[..])).unwrap_or_else(|_| die!("Error reading from the file/stream."))};
|
let n = if first_read > 0 {first_read} else {instream.read(&mut(bytes[..])).unwrap_or_else(|_| die!("Error reading from the file/stream."))};
|
||||||
if n == 0 { break; }
|
if n == 0 { break; }
|
||||||
first_read = 0;
|
first_read = 0;
|
||||||
let s = PayloadInfo::from(&(bytes[..])).unwrap_or_else(|e| die!("Invalid RLP in the file/stream: {:?}", e)).total();
|
let s = PayloadInfo::from(&(bytes[..])).unwrap_or_else(|e| die!("Invalid RLP in the file/stream: {:?}", e)).total();
|
||||||
bytes.resize(s, 0);
|
bytes.resize(s, 0);
|
||||||
instream.read_exact(&mut(bytes[8..])).unwrap_or_else(|_| die!("Error reading from the file/stream."));
|
instream.read_exact(&mut(bytes[READAHEAD_BYTES..])).unwrap_or_else(|_| die!("Error reading from the file/stream."));
|
||||||
do_import(bytes);
|
do_import(bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user