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 files_to_send = get_file_metas(&paths_to_send)?;
let offer_msg = FileOfferMsg::from(files_to_send.clone());
write_to_async(offer_msg, &mut stream1).await?;
// Peer B responds to the offer
let offer_msg: FileOfferMsg = read_from_async(&mut stream2).await?;
let response_msg = FileResponseMsg::accept_only_new_and_interrupted(
&offer_msg,
Path::new("save/the/files/here/"),
)?;
write_to_async(response_msg, &mut stream2).await?;
// Peer A sends the accepted files
let response_msg: FileResponseMsg = read_from_async(&mut stream1).await?;
send_files(&files_to_send, &response_msg, &mut stream1, |progress| {}).await?;
// Peer B receives the accepted files
let save_path = Path::new("save/the/files/here/");
receive_files(&offer_msg, &response_msg, save_path, &mut stream2, |progress| {}).await?;
Structs§
- File
Meta - Information about an offered file.
- File
Meta Local - Information about a locally stored file.
- File
Offer Msg - A
Vec
of file metadatas that this peer is offering to send. The other peer should reply withFileResponseMsg
. - File
Response Msg - The receiving peer should reply with this message to
FileOfferMsg
. Specifies which of the offered files the other peer should send. - Transfer
Report - Holds the status of a file transfer
Enums§
- Error
gday_file_transfer
error.
Constants§
- PROTOCOL_
VERSION - Version of the protocol. Different numbers wound indicate incompatible protocol breaking changes.
Functions§
- get_
file_ metas - Takes a list of distinct
paths
, each of which may be a directory or file. - read_
from - Reads a message from
reader
usingserde_json
. - read_
from_ async - Asynchronously reads a message from
reader
usingserde_json
. - receive_
files - Receives the requested files from
reader
. - send_
files - Transfers the requested files to
writer
. - write_
to - Writes
msg
towriter
usingserde_json
, and flushes. - write_
to_ async - Asynchronously writes
msg
towriter
usingserde_json
, and flushes.