read_write_from_disk
This commit is contained in:
parent
5673c03cfa
commit
b0beca5894
3 changed files with 49 additions and 0 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -12,3 +12,8 @@ Cargo.lock
|
||||||
|
|
||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "rust-tcp-file-transfer"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
36
src/main.rs
Normal file
36
src/main.rs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
use std::fs::File;
|
||||||
|
use std::net::{TcpListener, TcpStream};
|
||||||
|
use std::io::{Read, Write, self,copy};
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn read_file() -> File
|
||||||
|
{
|
||||||
|
File::open("/home/tahinli/Desktop/a.mp4").expect("Failed:Opening")
|
||||||
|
}
|
||||||
|
fn file_to_byte(mut file:File) ->Vec<u8>
|
||||||
|
{
|
||||||
|
let mut buf = vec![];
|
||||||
|
match File::read_to_end(&mut file, &mut buf)
|
||||||
|
{
|
||||||
|
Ok(size) => println!("Done:Reading\nFile Size = {} Bytes", size),
|
||||||
|
Err(err_val) => println!("Failed:Reading {}", err_val),
|
||||||
|
}
|
||||||
|
buf
|
||||||
|
}
|
||||||
|
fn write_file(buf:Vec<u8>)
|
||||||
|
{
|
||||||
|
match File::write_all(&mut File::create("/home/tahinli/Desktop/b.mp4").expect("Failed to create file"), &buf)
|
||||||
|
{
|
||||||
|
Ok(_) => println!("Done:Writing"),
|
||||||
|
Err(err_val) => println!("Failed:Writing {}", err_val),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn main()
|
||||||
|
{
|
||||||
|
println!("Hello, world!");
|
||||||
|
write_file(file_to_byte(read_file()));
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue