const fs = require('fs');
const https = require('https');

function downloadImage(url, filename) {
  // Create a new request object.
  const request = https.request(url, (response) => {
    // Check the response status code.
    if (response.statusCode !== 200) {
      // If the response status code is not 200, throw an error.
      throw new Error(`Error downloading image: ${response.statusCode}`);
    }

    // Create a new stream to write the image data to a file.
    const stream = fs.createWriteStream(filename);

    // Write the image data to the stream.
    response.pipe(stream);

    // Once the stream is closed, the image has been downloaded.
    stream.on('close', () => {
      console.log(`Image downloaded to ${filename}`);
    });
  });

  // Start the request.
  request.end();
}

// Example usage.
downloadImage('https://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Tux.svg/1200px-Tux.svg.png', 'tux.png');
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence