Skip to main content

File Transfer Flow

ErikrafT Drop implements a sophisticated file transfer system that handles everything from small text messages to large multi-gigabyte files. The system uses WebRTC DataChannels for direct peer-to-peer transfers with WebSocket fallback when necessary.

Transfer Lifecycle Overview

File Selection and Metadata

File Processing

MIME Type Detection

The system automatically detects and adds missing MIME types:

Transfer Request Protocol

Request Message Structure

Request Handling

File Chunking System

FileChunker Class

The FileChunker class breaks large files into manageable chunks:

Chunk Reading Process

Transfer Execution

Header Transmission

Progress Tracking

Partition Management

File Reception and Assembly

FileDigester Class

The FileDigester class reassembles received chunks:

Message Types and Protocols

Transfer Control Messages

Request Message

Response Message

Header Message

Progress Message

Partition Messages

Completion Messages

Error Handling and Recovery

Transfer Cancellation

Connection Error Handling

Transfer Completion

Performance Optimizations

Memory Management

  • Streaming: Files are processed in chunks to prevent memory overload
  • Buffer Cleanup: Automatic cleanup of completed transfers
  • iOS Limits: Special handling for iOS memory constraints

Network Efficiency

  • Chunk Size: 64KB chunks balance memory usage and network efficiency
  • Partition Tracking: 1MB partitions for progress reporting
  • Binary Transfer: Direct binary data transfer via DataChannels

Progress Feedback

  • Real-time Updates: Continuous progress reporting during transfer
  • Partition Tracking: Granular progress for large files
  • UI Integration: Seamless integration with user interface

WebSocket Fallback

When WebRTC is unavailable, transfers fall back to WebSocket:

Base64 Encoding

This file transfer system provides robust, efficient file sharing with comprehensive error handling and fallback mechanisms for maximum compatibility.