Skip to content

mattmassicotte/Packet

Build Status Platforms Documentation

Packet

A collection of utilities for working with Data and AsyncSequence.

Lots of stuff here is Foundation-specific. But, the idea is to compliment async-algorithms, not overlap.

Integration

dependencies: [
    .package(url: "https://github.com/mattmassicotte/Packet", branch: "main")
]

Usage

FileHandle support:

let fileHandle = FileHandle(...)

for await data in fileHandle.chunks {
    // use Data value here
}

URLSession support. This offers a considerable performance benefit.

let stream = URLSession.shared.chunks(for: url)
for try await data in stream {
    // use Data value here
}

Sometimes, to make things work with an existing API, you need to un-chunk a sequence. AsyncByteSequence converts a sequence of Data into a sequence of UInt8. This is inherently less-efficient, but can be a lot less work than changing the consumer.

let bytes = AsyncByteSequence(dataSequence)

for try await byte in bytes {
    // one byte at a time
}

Contributing and Collaboration

I'd love to hear from you! Get in touch via mastodon, an issue, or a pull request.

I prefer collaboration, and would love to find ways to work together if you have a similar project.

I prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.

By participating in this project you agree to abide by the Contributor Code of Conduct.

Releases

No releases published

Sponsor this project

 

Languages