跳到主要内容

函数: stringStream()

stringStream(options, cb): Writable

创建一个流,将字符串序列解析为文档。

该流是一个Writable流,接受字符串。当流结束时,回调函数会用加载的文档进行调用。

参数

options: CheerioOptions

传递给 Cheerio 的选项。

cb

流结束时调用的回调函数。

返回值

Writable

可写流。

示例

import * as cheerio from 'cheerio';
import * as fs from 'fs';

const writeStream = cheerio.stringStream({}, (err, $) => {
if (err) {
// Handle error
}

console.log($('h1').text());
// Output: Hello, world!
});

fs.createReadStream('my-document.html', { encoding: 'utf8' }).pipe(
writeStream,
);

定义于

src/index.ts:138