Skip to content

What is the best way to handle parsing of large files ? #246

Closed Answered by mackoj
mackoj asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @stephencelis,

I did arrive at an API that I find simple and that integrates pretty well with the actual API of swift-parsing.
Instead of calling .parse on a parser we can call .steam it return an AsyncThrowingStream<ParserStreamProgression<Output>, Error>.

/* AsyncThrowingStream<ParserStreamProgression<Output>, Error> */
for try await parsed in someParser.stream(inputFileURL: inputFileURL) {
  switch parsed {
   case .start:
     print("The parsing processing process has started")
   case let .progress(current, total, parsed):
     print("Have found \(parsed.count) elements.")
   case let .finish(parsed):
     print("Have found \(parsed.count) elements.")
  }
}

The steam function is c…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@mackoj
Comment options

@mackoj
Comment options

@mackoj
Comment options

Comment options

You must be logged in to vote
1 reply
@mackoj
Comment options

Answer selected by mackoj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants