{"size": 899, "ext": "js", "max_stars_repo_path": "node_modules/grunt-contrib-imagemin/node_modules/image-min/node_modules/optipng-bin/stream.js", "max_stars_repo_name": "ornl-sava/cms-geovar", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/grunt-contrib-imagemin/node_modules/image-min/node_modules/optipng-bin/stream.js", "max_issues_repo_name": "ornl-sava/cms-geovar", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/grunt-contrib-imagemin/node_modules/image-min/node_modules/optipng-bin/stream.js", "max_forks_repo_name": "ornl-sava/cms-geovar", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.9722222222, "max_line_length": 97, "alphanum_fraction": 0.553948832}
#!/usr/bin/env node
'use strict';

var concat = require('concat-stream');
var fs = require('fs');
var optipng = require('./').path;
var rm = require('rimraf');
var spawn = process.platform === 'win32' ? require('win-spawn') : require('child_process').spawn;
var tempfile = require('tempfile');

/**
 * Streaming interface for OptiPNG
 */

process.stdin.pipe(concat(function (data) {
    var src = tempfile('.png');
    var dest = tempfile('.png');

    fs.writeFile(src, data, function (err) {
        var args = process.argv.slice(2).concat(['-out', dest, src]);
        var cp = spawn(optipng, args, { stdio: 'inherit' });

        if (err) {
            throw err;
        }

        cp.on('exit', function () {
            rm.sync(src);

            fs.createReadStream(dest).pipe(process.stdout).on('close', function () {
                rm.sync(dest);
            });
        });
    });
}));
