You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Curl保存Mastodon Streaming API输出至文件失败问题咨询

解决Mastodon Streaming API流式输出无法写入文件的问题

这跟文件类型完全没关系,问题出在curl的默认输出缓冲机制上。

Mastodon的Streaming API是持续输出小数据块的流式接口,而curl默认会缓冲输出内容,只有当缓冲区被填满时才会把数据写入文件——这就导致你看到的TXT文件一直是空的,其实数据还在内存缓冲区里没刷到磁盘。

解决方法很简单,给curl加上-N(或--no-buffer)参数禁用输出缓冲,这样数据就能实时写入文件:

curl -N -X GET 'https://masto.don/api/v1/streaming/public' -H 'Authorization: Bearer MYSUPERSECRETTOKEN' >> mastodon_stream.txt

另外也可以用stdbuf命令强制设置行缓冲,绕过bash的输出缓冲限制:

stdbuf -oL curl -X GET 'https://masto.don/api/v1/streaming/public' -H 'Authorization: Bearer MYSUPERSECRETTOKEN' >> mastodon_stream.txt

内容的提问来源于stack exchange,提问作者dude

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 07:07:04