Swiftpack.co - Cornucopia-Swift/CornucopiaStreams as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Cornucopia-Swift/CornucopiaStreams
Cornucopia Streams Library
.package(url: "https://github.com/Cornucopia-Swift/CornucopiaStreams.git", from: "0.9.2")

CornucopiaStreams

:shell: The "horn of plenty" – a symbol of abundance.

SwiftPM Swift

Introduction

This library provides a convenient and extensible way to get an I/O stream pair to an URL – supporting various schemes, such as TCP, TTY, BLE, and EA.

Foundation comes with getStreamsToHost(withName:port:inputStream:outputStream:), which is clumsy to use and limited to TCP. CornucopiaStreams adds support for communicating with TTYs, external accessories (using the ExternalAccessory framework), and Bluetooth Low Energy (BLE) devices (using the CoreBluetooth framework).

On non-Apple-platforms, only TCP and TTY are supported, as both ExternalAccessory and CoreBluetooth are private Apple frameworks – it might be interesting to evaluate BluetoothLinux.

Usage

Open a connection to a TTY:

import CornucopiaStreams

let url = URL(string: "tty:///dev/cu.serial-123456")!
Stream.CC_getStreamPair(to: url) { result in
    guard case .success(let (inputStream, outputStream)) = result else { fatalError() }
    … do something with the streams …
}

Open a connection to a TCP host:

import CornucopiaStreams

let url = URL(string: "tcp://192.168.0.10:35000")!
Stream.CC_getStreamPair(to: url) { result in
    guard case .success(let (inputStream, outputStream)) = result else { fatalError() }
    … do something with the streams …
}

Open a connection to an external accessory:

import CornucopiaStreams

let url = URL(string: "ea://com.obdlink")!
Stream.CC_getStreamPair(to: url) { result in
    guard case .success(let (inputStream, outputStream)) = result else { fatalError() }
    … do something with the streams …
}

Open a connection to a BLE device:

import CornucopiaStreams

let url = URL(string: "ble://FFF0")!
Stream.CC_getStreamPair(to: url) { result in
    guard case .success(let (inputStream, outputStream)) = result else { fatalError() }
    … do something with the streams …
}

Some of the streams provide metadata, e.g., the name for BLE devices, which you can access via the CC_meta property.

Contributions

Feel free to use under the terms of the MIT, if you find anything helpful here. Contributions are always welcome! Stay safe and sound!

GitHub

link
Stars: 1
Last commit: 6 hours ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

CornucopiaStreams 0.9.2
6 days ago

Last release pre-iOS15/tvOS15/watchOS8/macOS12

Due to a source-incompatible change in the Apple CoreBluetooth API, further versions of this library will require the very latest set of Apple platforms.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics