You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const zlib = require("zlib");
|
|
|
|
|
|
|
|
const decodeString = require("@promistream/decode-string");
|
|
|
|
const fromNodeStream = require("@promistream/from-node-stream");
|
|
|
|
const parseSitemap = require("@promistream/parse-sitemap");
|
|
|
|
const pipe = require("@promistream/pipe");
|
|
|
|
|
|
|
|
module.exports = function parseSitemapResponse(response, url) {
|
|
|
|
// NOTE: Explicitly specifying the URL is meant only for cases where bhttp is not used
|
|
|
|
let requestURL = (url != null)
|
|
|
|
? url
|
|
|
|
: response.request.url;
|
|
|
|
|
|
|
|
return pipe([
|
|
|
|
fromNodeStream.fromReadable(response),
|
|
|
|
(requestURL.endsWith(".gz"))
|
|
|
|
? fromNodeStream(zlib.createGunzip())
|
|
|
|
: null,
|
|
|
|
decodeString("utf8"),
|
|
|
|
parseSitemap(),
|
|
|
|
]);
|
|
|
|
};
|