Crate gday_file_transfer
source ·Expand description
Note: this crate is still in early-development, so expect breaking changes.
This library lets you offer and transfer files to another peer, assuming you already have a reliable connection established.
§Example
The peers first establish a direct TCP connection using gday_hole_punch, and encrypt it with gday_encryption.
Peer A and peer B are on different computers in this example.
// Peer A offers files and folders they'd like to send
let paths_to_send = ["folder/to/send/".into(), "a/file.txt".into()];
let files_to_send = get_file_metas(&paths_to_send)?;
let offer_msg = FileOfferMsg::from(files_to_send.clone());
write_to(offer_msg, &mut stream)?;
// Peer B responds to the offer
let offer_msg: FileOfferMsg = read_from(&mut stream)?;
let response_msg = FileResponseMsg::accept_only_new_and_interrupted(
&offer_msg,
Path::new("save/the/files/here/"),
)?;
write_to(response_msg, &mut stream)?;
// Peer A sends the accepted files
let response_msg: FileResponseMsg = read_from(&mut stream)?;
send_files(&files_to_send, &response_msg, &mut stream, |progress| {})?;
// Peer B receives the accepted files
let save_path = Path::new("save/the/files/here/");
receive_files(&offer_msg, &response_msg, save_path, &mut stream, |progress| {})?;Structs§
- Information about an offered file.
- Information about a locally stored file
- A
Vecof file metadatas that this peer is offering to send. The other peer should reply withFileResponseMsg. - The receiving peer should reply with this message to
FileOfferMsg. Specifies which of the offered files the other peer should send. - Holds the status of a file transfer
Enums§
gday_file_transfererror.
Functions§
- Takes a list of distinct
paths, each of which may be a directory or file. - Read a message from
readerusingserde_json. - Receives the requested files from
reader. - Transfers the requested files to
writer.