Crate gday_file_transfer

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

FileMetadata
Information about an offered file.
FileOfferMsg
Offer of files to send.
FileRequestsMsg
Reply to FileOfferMsg.
LocalFileOffer
A FileOfferMsg along with local paths to the offered files.
SingleFileRequest
A part of FileRequestsMsg.
TransferReport
Holds the status of a file transfer

Enums§

Error
gday_file_transfer error.

Constants§

PROTOCOL_VERSION
Protocol version.

Functions§

create_file_offer
Returns a LocalFileOffer referring to all the files and directories within paths.
detect_interrupted_download
Checks for interrupted download.
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.