
Research
/Security News
Mini Shai-Hulud Campaign Hits Red Hat Cloud Services npm Packages
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.
fetch-stream-reader
Advanced tools
A lightweight client for reading streaming HTTP responses using Fetch and ReadableStream.
一个轻量级的客户端,基于 fetch() 与 ReadableStream,用于处理流式 HTTP 响应数据。
# 使用 pnpm
pnpm add fetch-stream-reader
# 使用 npm
npm install fetch-stream-reader
# 使用 yarn
yarn add fetch-stream-reader
import FetchStreamReader from 'fetch-stream-reader'
const client = new FetchStreamReader('https://api.example.com/stream', {
Authorization: 'Bearer token'
})
client.on('stream-start', () => {
console.log('开始建立连接和读取流')
})
client.on('stream-message', ({ detail }) => {
console.log('收到数据:', detail)
})
client.on('stream-error', ({ detail }) => {
console.log('流错误:', detail.error)
})
client.on('stream-end', () => {
console.log('流已结束')
})
client.on('stream-abort', () => {
console.log('流已被中止')
})
// 发送请求并建立流连接。
await client.start({ prompt: 'Hello' })
| 事件名称 | 描述 |
|---|---|
stream-start | 已成功建立连接并开始读取流数据时触发 |
stream-message | 每接收到一条完整且可解析的数据时触发(通常为 JSON 对象) |
stream-error | 请求失败或数据解析错误时触发,detail 包含原始数据和错误信息 |
stream-end | 流被服务端正常关闭时触发 |
stream-abort | 客户端主动调用 stop() 手动中止连接时触发 |
new FetchStreamReader(url: string, headers?: Record<string, string>)创建流式读取器实例。
| 参数 | 类型 | 描述 |
|---|---|---|
url | string | 接口地址(必须为 POST 请求地址) |
headers | Record<string, string> | 可选的请求头(如认证) |
start(payload: object): Promise<void>发送请求并建立流连接。
on(eventName: string, handler: (event: CustomEvent) => void)注册事件监听器。
off(eventName: string, handler?: (event: CustomEvent) => void)移除事件监听器。
stop(): void中止当前流连接,并清理相关资源。
如果你正好在构建一个流式通信的 Web 项目,希望 fetch-stream-reader 能帮你少写点重复代码,多专注于用户体验。
如果你在使用过程中遇到问题,或者对 fetch-stream-reader 感兴趣,欢迎一起交流探讨。
📬 可加微信(备注 “npm + 昵称”):g_adiu
FAQs
A lightweight client for reading streaming HTTP responses using Fetch and ReadableStream.
We found that fetch-stream-reader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.

Research
/Security News
The North Korean malware loader hides in a Packagist-listed package and its GitHub branch to fetch and execute remote code in a likely Contagious Interview-style lure.

Security News
The Rust project is moving toward formal rules on LLM use in contributions after months of internal debate over maintainer burden, code quality, and contributor experience.