pretty_close

This commit is contained in:
Ahmet Kaan GÜMÜŞ 2023-10-12 02:54:57 +03:00
parent c6b5dcdd9d
commit 2a13e072b2

View file

@ -5,7 +5,7 @@ use std::io::{Read, Write, self, BufWriter, BufReader, BufRead};
use std::env::{self}; use std::env::{self};
const BUFFER_SIZE:usize = 100000; const BUFFER_SIZE:usize = 1024;
struct FileInfo struct FileInfo
{ {
@ -66,6 +66,7 @@ impl FileInfo
Err(err_val) => Err(err_val) =>
{ {
println!("Error: Open File -> {} | Error: {}", self.location, err_val); println!("Error: Open File -> {} | Error: {}", self.location, err_val);
return;
} }
} }
@ -88,6 +89,7 @@ impl FileInfo
Err(err_val) => Err(err_val) =>
{ {
println!("Error: Send Terminator -> {} | Error: {}", self.location, err_val); println!("Error: Send Terminator -> {} | Error: {}", self.location, err_val);
return;
} }
} }
match stream_writer.flush() match stream_writer.flush()
@ -99,6 +101,7 @@ impl FileInfo
Err(err_val) => Err(err_val) =>
{ {
println!("Error: Flush Handshake -> {} | Error: {}", self.location, err_val); println!("Error: Flush Handshake -> {} | Error: {}", self.location, err_val);
return;
} }
} }
let mut handshake_callback:Vec<u8> = Vec::new(); let mut handshake_callback:Vec<u8> = Vec::new();
@ -143,13 +146,12 @@ impl FileInfo
Ok(read_size) => Ok(read_size) =>
{ {
self.size_current += read_size; self.size_current += read_size;
if iteration != 0 //println!("{} | {} | {:#?}", iteration,buffer.len(), buffer);
{
match stream_writer.write_all(&mut buffer) match stream_writer.write_all(&mut buffer)
{ {
Ok(_) => Ok(_) =>
{ {
//println!("Done: Send Bytes -> {} | Iteration = {}", self.location, iteration); println!("Done: Send Bytes -> {} | Iteration = {}", self.location, iteration);
} }
Err(err_val) => Err(err_val) =>
{ {
@ -157,33 +159,6 @@ impl FileInfo
return; return;
} }
} }
}
else
{
let mut last_buffer:Vec<u8> = (&buffer[..(self.metadata.as_ref().unwrap().len()%BUFFER_SIZE as u64)as usize]).to_vec();
match stream_writer.write_all(&mut last_buffer)
{
Ok(_) =>
{
println!("Done: Send Last Bytes -> {}", self.location);
}
Err(err_val) =>
{
println!("Error: Send Last Bytes -> {} | Error: {}", self.location, err_val);
}
}
}
match stream_writer.write_all(String::from("\n").as_bytes())
{
Ok(_) =>
{
//println!("Done: Send Terminator -> {}", self.location);
}
Err(err_val) =>
{
println!("Error: Send Terminator -> {} | Error: {}", self.location, err_val);
}
}
match stream_writer.flush() match stream_writer.flush()
{ {
Ok(_) => Ok(_) =>
@ -193,6 +168,7 @@ impl FileInfo
Err(err_val) => Err(err_val) =>
{ {
println!("Error: Flush -> {} | Error: {}", self.location, err_val); println!("Error: Flush -> {} | Error: {}", self.location, err_val);
return;
} }
} }
@ -200,6 +176,7 @@ impl FileInfo
Err(err_val) => Err(err_val) =>
{ {
println!("Error: File to Byte -> {} | Error: {}", self.location, err_val); println!("Error: File to Byte -> {} | Error: {}", self.location, err_val);
return;
} }
} }
@ -277,37 +254,44 @@ impl FileInfo
{ {
Ok(_) => Ok(_) =>
{ {
self.size_current += buffer.len();
//println!("{} | {:#?}", iteration, buffer);
if iteration != 0 if iteration != 0
{ {
match file_writer.write_all(&mut buffer) match file_writer.write_all(&mut buffer)
{ {
Ok(_) => Ok(_) =>
{ {
self.size_current += buffer.len(); println!("Done: Write -> {} bytes | Iteration = {}", &mut self.size_current, iteration);
//println!("Done: Write -> {} bytes | Iteration = {}", &mut self.size_current, iteration); }
Err(err_val) =>
{
println!("Error: Write -> {} | Error: {}", self.location,err_val);
return;
} }
Err(err_val) => println!("Error: Write {}", err_val),
} }
} }
else else
{ {
let mut last_buffer:Vec<u8> = (&buffer[..(size%BUFFER_SIZE as u64)as usize]).to_vec(); match file_writer.write_all(&mut buffer[..(size%BUFFER_SIZE as u64)as usize])
match stream_writer.write_all(&mut last_buffer)
{ {
Ok(_) => Ok(_) =>
{ {
println!("Done: Recv Last Bytes -> {}", self.location); println!("Done: Write Last -> {} bytes | Iteration = {}", &mut self.size_current, iteration);
} }
Err(err_val) => Err(err_val) =>
{ {
println!("Error: Recv Last Bytes -> {} | Error: {}", self.location, err_val); println!("Error: Write Last -> {} | Error: {}", self.location,err_val);
return;
} }
} }
} }
} }
Err(err_val) => Err(err_val) =>
{ {
println!("{} | {:#?}", iteration, buffer);
println!("Error: Recv Bytes -> {} | Error: {}", self.location, err_val); println!("Error: Recv Bytes -> {} | Error: {}", self.location, err_val);
return;
} }
} }
} }
@ -412,8 +396,6 @@ fn take_arg() -> String
env::args().last().as_deref().unwrap_or("default").to_string() env::args().last().as_deref().unwrap_or("default").to_string()
} }
fn main() fn main()
{ {
//DONT FORGET //DONT FORGET