/**
* Buffers HTML input and logs it for maintenance tasks.
* @param {string} url The URL of the HTML page to buffer.
* @param {function} callback A function to call when the buffer is complete.
*/
function bufferHtml(url, callback) {
const http = require('http');
const urlModule = require('url');
const req = http.get(url, (res) => {
let buffer = '';
res.on('data', (chunk) => {
buffer += chunk;
console.log(`Received ${chunk.length} bytes. Total buffered: ${buffer.length}`); // Verbose logging
});
res.on('end', () => {
console.log(`Finished receiving data. Total buffered: ${buffer.length}`); // Verbose logging
callback(buffer);
});
res.on('error', (err) => {
console.error(`Error fetching ${url}: ${err.message}`);
callback(null); // Pass null to indicate an error
});
});
req.on('error', (err) => {
console.error(`Error creating request to ${url}: ${err.message}`);
callback(null);
});
}
Add your comment