Package-level declarations

Types

Link copied to clipboard
interface FileSaver

Stores received files, for ReceiveEvent.FileOffered.acceptInto. Use FileSaver.folder for a folder on the file system, or implement it for other storage, such as Android's MediaStore.

Link copied to clipboard
interface FolderUnpacker

How a received directory (a zip) is unpacked. Set it in WormholeConfig.folderUnpacker.

Link copied to clipboard
interface IncomingFile

A received file being written. The library writes to sink and closes it, then calls commit when all bytes arrived and were verified, or discard when the transfer failed.

Link copied to clipboard

A received directory being unpacked. The library calls createDirectory and createFile (paths are relative, use / and never contain ..), then commit when all files are written, or discard when unpacking failed.

Link copied to clipboard

The code does not have the form <number>-<word>[-<word>...].

Link copied to clipboard

The zip is damaged, unsafe (a path leaves the target folder) or larger than allowed.

Link copied to clipboard
class OutgoingFile(val name: String, val size: Long, val open: () -> RawSource)

A file to send. open returns a new source with the size bytes of the file each time it is called; the library calls it only when the transfer runs, and closes the source.

Link copied to clipboard
class PeerErrorException(val peerMessage: String) : WormholeException

The other side stopped with an error message.

Link copied to clipboard
sealed interface ReceiveEvent

Progress of a receive.

Link copied to clipboard
data class SavedFile(val name: String, val location: String)

Where a received file or folder was saved. location is a path or URI to show or open.

Link copied to clipboard
class SaveFailedException(message: String, cause: Throwable? = null) : WormholeException

A received file could not be stored, for example because the disk is full.

Link copied to clipboard
sealed interface SendEvent

Progress of a send.

Link copied to clipboard
sealed interface SendFileEvent : SendEvent
Link copied to clipboard
sealed interface SendTextEvent : SendEvent

Events emitted by Wormhole.sendText.

Link copied to clipboard

The mailbox server could not be reached, or the connection was lost.

Link copied to clipboard

The receiver declined the transfer.

Link copied to clipboard
class TransitException(message: String, cause: Throwable? = null) : WormholeException

The data connection (direct or through the transit relay) failed.

Link copied to clipboard
interface UnzipTarget

Where unzip puts the files. Paths are relative, use / and never contain ...

Link copied to clipboard
class Wormhole

Entry point of the library. Each call returns a cold Flow: the transfer starts when you collect it and is cancelled when you stop collecting. Failures are thrown as WormholeException subclasses.

Link copied to clipboard
data class WormholeConfig(val rendezvousUrl: String = DEFAULT_RENDEZVOUS_URL, val transitRelay: String? = DEFAULT_TRANSIT_RELAY, val appId: String = DEFAULT_APP_ID, val codeLength: Int = 2, val folderUnpacker: FolderUnpacker = FolderUnpacker.streaming())

Settings for a Wormhole. The defaults are compatible with the wormhole CLI.

Link copied to clipboard
open class WormholeException(message: String, cause: Throwable? = null) : Exception

Base class for all errors reported by this library.

Link copied to clipboard

The other side sent something that does not follow the protocol.

Link copied to clipboard

The mailbox server reported an error, for example crowded or a welcome error.

Link copied to clipboard

The two sides used different codes, so the keys do not match.

Link copied to clipboard
interface ZipReceiver

Receives the bytes of one zip for a FolderUnpacker.

Properties

Link copied to clipboard

Application ID used by the wormhole CLI and wormhole-william for text and file transfers.

Link copied to clipboard

Default Magic Wormhole rendezvous (mailbox) server, as used by the current wormhole CLI.

Link copied to clipboard

Default Magic Wormhole transit relay.

Functions

Link copied to clipboard
suspend fun unzip(zip: Path, folder: Path, maxBytes: Long = Long.MAX_VALUE, maxFiles: Int = Int.MAX_VALUE)

Unpacks the zip file zip into folder, which is created if needed. See the other unzip for the checks and for maxBytes and maxFiles.

suspend fun unzip(size: Long, open: (offset: Long) -> RawSource, target: UnzipTarget, maxBytes: Long = Long.MAX_VALUE, maxFiles: Int = Int.MAX_VALUE)

Unpacks a received directory (see ReceiveEvent.FileOffered.isDirectory) into target. Reads zips made by the wormhole CLI, wormhole-william and Wormhole.sendDirectory.