- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Node.js 中,我有一个可读流:
var rs = new (require('stream').Readable);
rs._read = function(size) {
// Implementation.
}
在这个 HTTP 服务器实例中读取这个流:
var http = require('http');
var server = http.createServer(function(req, res) {
var size = require('url').parse(req.url, true).query.size;
if (size) {
rs.pipe(res);
rs.read(parseInt(size));
}
res.end('');
});
server.listen(3001, function() {
console.log('Listening on 3001');
});
现在,当我 curl localhost:3001/?size=n
,其中 n 是任意整数,size
在rs._read(size)
永远是 16384!此数字是流的默认值 state.highWaterMark
,因为 rs._read()
称为 this._read(state.highWaterMark);
在lib/_stream_readable.js
.谁能解释一下? size
有什么意义?如果不使用参数?
谢谢。
最佳答案
看起来这只是流的 highWaterMark
和 not coincidentally默认的大小
。 Read more here
var stream = require("stream");
var rs = new stream.Readable();
{ _readableState:
{ highWaterMark: 16384,
buffer: [],
length: 0,
pipes: null,
pipesCount: 0,
flowing: false,
ended: false,
endEmitted: false,
reading: false,
calledRead: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
objectMode: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events: {},
_maxListeners: 10 }
关于javascript - 读取 ReadableStream 并指定大小参数 : Why does state. highWaterMark 总是作为大小传递给 ._read()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17710712/
我想从 Blob 中获得可读形式。 import {Readable} from 'stream'; const data: Blob = new Blob( ); const myReadable:
我有一个使用@types/whatwg-fetch 版本 0.0.32 的项目。 运行我的项目时出现以下错误。 ERROR in /node_modules/@types/whatwg-fetch/i
我使用 HTML 文件输入从我的设备存储中访问一个文件,然后我将该文件作为流读取。 是否有任何内置方法可以将每次读取的长度限制为特定字节数。 const stream = myFile.stream(
我想加载整个 fetch一口气响应,但似乎没有 readAll 或类似的功能。 从 ReadableStreamDefaultReader 读取每个字节的最高效方法是什么?成一个Uint8Array
我正在尝试使用 fetch与 ReadableStream 。在此示例中,ReadableStream 应该简单地无限期地重复“Some data...”。 fetch('/', { method
如何从 ReadableStream 对象获取信息? 我正在使用 Fetch API,但我没有从文档中看到这一点。 正文作为 ReadableStream 返回,我只想访问此流中的属性。在浏览器开发工
我正在使用的内部库提供 NodeJS.ReadableStream , 我需要传递给 nodemailer (附件),作为参数Readable . Argument of type 'Buffer
我从服务器接收到一个 ReadableStream,它是从我的 fetch 调用返回的。 返回一个 ReadableStream 但我不知道如何从这个阶段触发下载。我不能在 href 中使用 url,
我有一组从 fetch() 调用中返回的 Promise: const fetchResults = [ promise , promise , promise ] 每个 Promise 的 .bod
我有 PNG 图像作为 ReadableStream,我需要以这个 ReadableStream 作为源显示 html 元素 img。我应该把它转换成什么吗?或者我该怎么做? 谢谢你的回答 最佳答案
我正在尝试使用 StreamSaver 下载大文件 (500mb - 2gb) 它在 Chrome 上工作正常但是正如你在这里看到的 ReadableStream {locked: false} lo
我想在我的 NextJS 应用程序中显示 Google Place Photos。要从指定的 URL 获取这些图像,需要 API key ,但与此同时,我不想向公众公开此 API key 。 我的目标
我目前正在尝试创建一个实用程序来解析 PDF 中的注释。我可以很好地加载 PDF 文件,注释对象也很好,但我需要获取与这些注释相关的文本(带下划线、突出显示等)。 当我尝试使用失败的 getTextC
我有一个 React 应用程序,它向我的 Rails API 发送 POST 请求。我希望我的 API 端点生成一个 csv 文件,然后将该文件发送回 React 应用程序。我希望浏览器为最终用户下载
我查看了所有互联网,但无法为我的新项目找到解决方案。我正在使用 simple-git 包,类型定义包括对 ReadableStream 的几个引用。 Typescript 在转译过程中出现错误(“找不
我正在使用 ODATA NPM 包通过 REST 调用获取 ODATA。 (我认为这基本上只是一个用于获取的包装器)。 嗯,我正在使用await/try/catch来捕获错误,并且我想获取错误的正文。
我正在尝试实现可读流的 ._read 功能,当调用 ._read 并且没有数据时会出现问题,文档说我可以 push('') 直到有更多数据出现,并且我应该只在流永远不会有更多数据时 return fa
我想了解流的工作原理。我有一个 readableStream,我正在将其通过管道传输到 writableStream。 但是,当我这样做时,我在控制台中收到此错误。 无法在“ReadableStrea
我正在使用 fetch 从服务器动态加载图像。如何在我的 HTML 中使用返回的 ReadableStream 作为图像源?在下面的代码示例中,data.body 是一个 ReadableStream
我正在实现一个可读流。在我的 _read() 实现中,流的来源是需要异步调用的 Web 服务。为什么 _read() 不提供可在异步调用返回时调用的 done 回调函数? Transform 流和 W
我是一名优秀的程序员,十分优秀!