Crate gday_file_transfer

Source
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§

FileMeta
Information about an offered file.
FileMetaLocal
Information about a locally stored file.
FileOfferMsg
A Vec of file metadatas that this peer is offering to send. The other peer should reply with FileResponseMsg.
FileResponseMsg
The receiving peer should reply with this message to FileOfferMsg. Specifies which of the offered files the other peer should send.
TransferReport
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 using serde_json.
read_from_async
Asynchronously reads a message from reader using serde_json.
receive_files
Receives the requested files from reader.
send_files
Transfers the requested files to writer.
write_to
Writes msg to writer using serde_json, and flushes.
write_to_async
Asynchronously writes msg to writer using serde_json, and flushes.