修理Haskell导管中的流式HTTP块

发布于 2025-01-30 01:04:45 字数 732 浏览 4 评论 0原文

我是从地衣api中流媒体的棋子。建议进行流媒体,因为任何给定的用户都可以存储高达500,000个游戏。目的是在parsepgnstream导管中解析PGN。不幸的是,流块是任意的和pgn-agnostic的,这意味着必须有某种中间的导管块,使每个输入是完整的pgn bytestring一旦达到parsepgnstream

reqBr GET (url) NoReqBody opts $ \r -> do
      runConduitRes $ (responseBodySource r .| repairChunk .| parsePGNStream .| BS.sinkFile "./test.pgn")

我有一个部分PGN解析器,它递归地找到给定的bytestring中的第一个完整的pgn匹配,

stepParse i
  | valid = Just i
  | BS.null i = Nothing
  | otherwise = stepParse (BS.init i)
    where
      r = MP.parseMaybe pgn i
      valid = isJust r

如果我不得不猜测,该解决方案可能涉及某种类型的剩余的,它会输入不满意的输入。回到导管输入 - 但是我所做的一切似乎都是死胡同。如何实施此操作?

I'm streaming chess PGNs from the Lichess API. Streaming is recommended, since any given user could have up to ~500,000 games stored. The goal is to parse the PGNs in a parsePGNStream conduit as they're coming in. Unfortunately, the stream chunking is arbitrary and PGN-agnostic -- meaning there has to be some kind of intermediary conduit which concatenates chunks so that each piece of input is a complete PGN ByteString once it reaches parsePGNStream.

reqBr GET (url) NoReqBody opts $ \r -> do
      runConduitRes $ (responseBodySource r .| repairChunk .| parsePGNStream .| BS.sinkFile "./test.pgn")

I have a partial PGN parser which recursively finds the first complete PGN-match in a given ByteString

stepParse i
  | valid = Just i
  | BS.null i = Nothing
  | otherwise = stepParse (BS.init i)
    where
      r = MP.parseMaybe pgn i
      valid = isJust r

If I had to guess, the solution probably involves some kind leftover which feeds unconsumed input back to the conduit input -- but everything I do seems to be a dead end. How would one go about implementing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文