<commit_before>module.exports = image;

var debug = require('debug')('inliner');
var mime = require('mime');
var SVGO = require('svgo');
var svgo = new SVGO();
var Promise = require('es6-promise').Promise; // jshint ignore:line

function image(url) {
  url = url.replace(/\??#.*$/, '');
  var inliner = this;
  this.emit('progress', 'get image ' + url);
  return this.get(url, { encoding: 'binary' }).then(function then(res) {
    if (url.indexOf('data:') === 0) {
      return url;
    }

    debug('image loaded: %s', url);

    // if the url is SVG, let's compress and use the XML directly
    if (mime.lookup(url) === 'image/svg+xml' && !inliner.options.nosvg) {
      return new Promise(function (resolve, reject) {
        svgo.optimize(res.body.toString(), function (result) {<commit_msg>fix: don't try to encode SVG if there's no body<commit_after>module.exports = image;

var debug = require('debug')('inliner');
var mime = require('mime');
var SVGO = require('svgo');
var svgo = new SVGO();
var Promise = require('es6-promise').Promise; // jshint ignore:line

function image(url) {
  url = url.replace(/\??#.*$/, '');
  var inliner = this;
  this.emit('progress', 'get image ' + url);
  return this.get(url, { encoding: 'binary' }).then(function then(res) {
    if (url.indexOf('data:') === 0) {
      return url;
    }

    debug('image loaded: %s', url);

    // if the url is SVG, let's compress and use the XML directly
    if (res.body && mime.lookup(url) === 'image/svg+xml' &&
      !inliner.options.nosvg) {
      return new Promise(function (resolve, reject) {
        svgo.optimize(res.body.toString(), function (result) {
{'fraction_non_alphanumeric': 0.18392204628501826, 'fraction_numerical': 0.00243605359317905, 'mean_word_length': 3.628169014084507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4171920', 'n_tokens_mistral': 564, 'n_tokens_neox': 542, 'n_words': 150}