Expand description
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 offer = create_file_offer(&paths_to_send)?;
write_to_async(&offer.offer, &mut stream1).await?;
// Peer B responds to the offer
let offer_msg: FileOfferMsg = read_from_async(&mut stream2).await?;
let requests_msg = FileRequestsMsg::accept_only_new_and_interrupted(
&offer_msg,
Path::new("save/the/files/here/"),
)?;
write_to_async(requests_msg, &mut stream2).await?;
// Peer A sends the accepted files
let requests_msg: FileRequestsMsg = read_from_async(&mut stream1).await?;
send_files(&offer, &requests_msg, &mut stream1, |progress| {}).await?;
// Peer B receives the accepted files
let save_path = Path::new("save/the/files/here/");
receive_files(
&offer_msg,
&requests_msg,
save_path,
&mut stream2,
|progress| {},
)
.await?;Modules§
- save_
path - Extra helper functions for download file paths.
Structs§
- File
Metadata - Information about an offered file.
- File
Offer Msg - Offer of files to send.
- File
Requests Msg - Reply to
FileOfferMsg. - Local
File Offer - A
FileOfferMsgalong with local paths to the offered files. - Single
File Request - A part of
FileRequestsMsg. - Transfer
Report - Holds the status of a file transfer
Enums§
- Error
gday_file_transfererror.
Constants§
- PROTOCOL_
VERSION - Protocol version.
Functions§
- create_
file_ offer - Returns a
LocalFileOfferreferring to all the files and directories withinpaths. - detect_
interrupted_ download - Checks for interrupted download.
- read_
from - Reads a message from
readerusingserde_json. - read_
from_ async - Asynchronously reads a message from
readerusingserde_json. - receive_
files - Receives the requested files from
reader. - send_
files - Transfers the requested files to
writer. - write_
to - Writes
msgtowriterusingserde_json, and flushes. - write_
to_ async - Asynchronously writes
msgtowriterusingserde_json, and flushes.