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§

Enums§

  • gday_file_transfer error.

Functions§