saagarjha / unxip

A fast Xcode unarchiver
GNU Lesser General Public License v3.0
867 stars 39 forks source link

make AsyncThrowingStream extension init public #35

Open MattKiazyk opened 12 months ago

MattKiazyk commented 12 months ago

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 commented 12 months ago

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 commented 12 months ago

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 commented 12 months ago

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 commented 12 months ago

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 commented 12 months ago

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