Skip to main content

Function: stringStream()

stringStream(options, cb): Writable

Creates a stream that parses a sequence of strings into a document.

The stream is a Writable stream that accepts strings. When the stream is finished, the callback is called with the loaded document.

Parameters

options

CheerioOptions

The options to pass to Cheerio.

cb

(err, $) => void

The callback to call when the stream is finished.

Returns

Writable

The writable stream.

Example

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,
);

Defined in

src/index.ts:138