/* eslint-disable */

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

'use strict';

const path = require('path');
const fs = require('fs');
global.DataView = global.DataView || require('jdataview');
global.DOMParser = global.DOMParser || require('xmldom').DOMParser;

const ExifReader = require('./dist/exif-reader');

if (process.argv.length < 3) {
    console.log(`Usage: node ${path.basename(__filename)} <filename>`);
    process.exit();
}

const filePath = process.argv[2];

fs.readFile(filePath, function (error, data) {
    if (error) {
        console.error('Error reading file.');
        process.exit(1);
    }

    try {
        const tags = ExifReader.load(data.buffer, {expanded: true});
        listTags(tags);
    } catch (error) {
        console.error(error);
        process.exit(1);
    }
});

function listTags(tags) {
    for (const type in tags) {
        for (const name in tags[type]) {
            console.log(`${type}, ${name}: ${tags[type][name].description}`);
        }
    }
}
