修理Haskell导管中的流式HTTP块
我是从地衣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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论