Skip to content

Commit

Permalink
Unify UnxipStream apertures
Browse files Browse the repository at this point in the history
  • Loading branch information
saagarjha committed Oct 7, 2024
1 parent 51dd1ae commit 25665aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import libunxip

let data = DataReader(descriptor: STDIN_FILENO)
var directories = 0
for try await file in Unxip.makeStream(from: .xip(input: data), to: .files, input: data) where file.type == .directory {
for try await file in Unxip.makeStream(from: .xip(), to: .files(), input: data) where file.type == .directory {
directories += 1
}
print("This XIP contains \(directories) directories")
Expand Down
16 changes: 6 additions & 10 deletions unxip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1319,23 +1319,19 @@ public enum Disk: StreamAperture {
}

public struct UnxipStream<T: StreamAperture> {
public static func xip<S: AsyncSequence>(wrapping: @autoclosure () -> S) -> UnxipStream<XIP<S>> where S.Element: RandomAccessCollection, S.Element.Element == UInt8 {
return .init()
}

public static func xip<S: AsyncSequence>(input: @autoclosure () -> DataReader<S>) -> UnxipStream<XIP<S>> where S.Element: RandomAccessCollection, S.Element.Element == UInt8 {
return .init()
public static func xip<S: AsyncSequence>() -> UnxipStream<XIP<S>> where S.Element: RandomAccessCollection, S.Element.Element == UInt8 {
.init()
}

public static var chunks: UnxipStream<Chunks> {
public static func chunks() -> UnxipStream<Chunks> {
.init()
}

public static var files: UnxipStream<Files> {
public static func files() -> UnxipStream<Files> {
.init()
}

public static var disk: UnxipStream<Disk> {
public static func disk() -> UnxipStream<Disk> {
.init()
}
}
Expand Down Expand Up @@ -1589,7 +1585,7 @@ extension AsyncSequence where Element: Sendable, AsyncIterator: Sendable {
}
}

for try await file in Unxip.makeStream(from: .xip(wrapping: input), to: .disk, input: DataReader(data: input), nil, nil, .init(compress: options.compress, dryRun: options.dryRun)) {
for try await file in Unxip.makeStream(from: .xip(), to: .disk(), input: DataReader(data: input), nil, nil, .init(compress: options.compress, dryRun: options.dryRun)) {
await statistics.note(file)
if options.verbose {
print(file.name)
Expand Down

0 comments on commit 25665aa

Please sign in to comment.