Skip to content

Add helper collect method to collect a string up to a sequence #14

@dimitribouniol

Description

@dimitribouniol
extension AsyncIteratorProtocol where Element == UInt8 {
    public mutating func collect(
        utf8: String.Type,
        upToExcluding termination: StringProtocol,
        throwsIfOver maximumBufferSize: Int
    ) async throws -> String? {
        let bytes = try await iterator.collect(upToExcluding: termination.utf8, throwsIfOver: throwsIfOver))
        return bytes.map { String(decoding: $0, as: UTF8.self) }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions