Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make AsyncThrowingStream extension init public #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MattKiazyk
Copy link
Contributor

When using AsyncThrowingStream similar to how the CLI works, I get errors with the following code:

let handle: FileHandle
handle = try FileHandle(forReadingFrom: input)
        
let file = AsyncThrowingStream(erasing: DataReader.data(readingFrom: handle.fileDescriptor))

returns Cannot convert value of type 'AsyncThrowingStream<[UInt8], any Error>' to expected argument type '() async throws -> Element?'

@saagarjha
Copy link
Owner

Ah, that's an oversight, thanks for identifying this. With that said I think the route I want to take here is to make lockstepSplit available on AsyncSequence (I assume that's why you want to erase it?) I eventually want to the entire API exposed as some AsyncSequence when typed throws lands, I'm just using AsyncThrowingStream as a stopgap to avoid exposing internal stream types to clients.

@MattKiazyk
Copy link
Contributor Author

So my ultimate goal was to use the libunxip inside Xcodes - but not having to deal with all the async stream stuff for the time being. Previously was using the CLI, where I could just pass in a single file and unxip would do everything.

So I was working on a Unxip.unxip(input: URL) async throws inside of the library so that, if somebody wanted, could use the library with a single source.

@saagarjha
Copy link
Owner

If you just need a one-shot decompression, you should be good with this:

let handle = try FileHandle(forReadingFrom: input)
let data = DataReader.data(descriptor: handle.fileDescriptor)

for try await _ in Unxip.makeStream(from: .xip(input: data), to: .disk, input: data) {
}

@MattKiazyk
Copy link
Contributor Author

If you just need a one-shot decompression, you should be good with this:

let handle = try FileHandle(forReadingFrom: input)
let data = DataReader.data(descriptor: handle.fileDescriptor)

for try await _ in Unxip.makeStream(from: .xip(input: data), to: .disk, input: data) {
}

I could be way off but if i'm understanding all the code correctly, this isn't currently possible because UnxipStream requires a AsyncSequence which Datareader only produces a AsyncThrowingStream

Cannot convert value of type 'AsyncThrowingStream<[UInt8], any Error>' to expected argument type 'DataReader<S>'

@saagarjha
Copy link
Owner

That'll teach me for writing this from memory. Use let data = DataReader(descriptor: handle.fileDescriptor) instead

@saagarjha saagarjha force-pushed the main branch 3 times, most recently from 0f301d3 to 24237f8 Compare September 30, 2024 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants