UNPKG

2.41 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Transform, TransformOptions, TransformCallback, Readable } from 'stream';
3import { SitemapItemLoose, ErrorLevel, ErrorHandler } from './types';
4export declare const stylesheetInclude: (url: string) => string;
5export interface NSArgs {
6 news: boolean;
7 video: boolean;
8 xhtml: boolean;
9 image: boolean;
10 custom?: string[];
11}
12export declare const closetag = "</urlset>";
13export interface SitemapStreamOptions extends TransformOptions {
14 hostname?: string;
15 level?: ErrorLevel;
16 lastmodDateOnly?: boolean;
17 xmlns?: NSArgs;
18 xslUrl?: string;
19 errorHandler?: ErrorHandler;
20}
21/**
22 * A [Transform](https://nodejs.org/api/stream.html#stream_implementing_a_transform_stream)
23 * for turning a
24 * [Readable stream](https://nodejs.org/api/stream.html#stream_readable_streams)
25 * of either [SitemapItemOptions](#sitemap-item-options) or url strings into a
26 * Sitemap. The readable stream it transforms **must** be in object mode.
27 */
28export declare class SitemapStream extends Transform {
29 hostname?: string;
30 level: ErrorLevel;
31 hasHeadOutput: boolean;
32 xmlNS: NSArgs;
33 xslUrl?: string;
34 errorHandler?: ErrorHandler;
35 private smiStream;
36 lastmodDateOnly: boolean;
37 constructor(opts?: SitemapStreamOptions);
38 _transform(item: SitemapItemLoose, encoding: string, callback: TransformCallback): void;
39 _flush(cb: TransformCallback): void;
40}
41/**
42 * Converts a readable stream into a promise that resolves with the concatenated data from the stream.
43 *
44 * The function listens for 'data' events from the stream, and when the stream ends, it resolves the promise with the concatenated data. If an error occurs while reading from the stream, the promise is rejected with the error.
45 *
46 * ⚠️ CAUTION: This function should not generally be used in production / when writing to files as it holds a copy of the entire file contents in memory until finished.
47 *
48 * @param {Readable} stream - The readable stream to convert to a promise.
49 * @returns {Promise<Buffer>} A promise that resolves with the concatenated data from the stream as a Buffer, or rejects with an error if one occurred while reading from the stream. If the stream is empty, the promise is rejected with an EmptyStream error.
50 * @throws {EmptyStream} If the stream is empty.
51 */
52export declare function streamToPromise(stream: Readable): Promise<Buffer>;