"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var electron_1 = require("electron");
var fs = require("fs");
var imageType = require('image-type');
var download = function (fileName, bytes) {
    return new Promise(function (resolve, reject) {
        var options = {};
        var type = imageType(bytes);
        if (fileName) {
            options.defaultPath = fileName;
        }
        if (type && type.ext) {
            options.filters = [
                {
                    extensions: [type.ext],
                    name: 'Images',
                },
            ];
        }
        electron_1.dialog.showSaveDialog(options, function (chosenPath) {
            if (chosenPath !== undefined) {
                fs.writeFile(chosenPath, new Buffer(bytes.buffer), function (error) { return (error ? reject(error) : resolve()); });
            }
            else {
                reject('no path specified');
            }
        });
    });
};
exports.download = download;
//# sourceMappingURL=download.js.map