// Common routines for handling archives.

init("archive");

var Archive = {
    nFiles: 0, // number of files in archive
    nDirs: 0, // number of directories in archive
    nSize: 0, // total unpacked size of all files
    nPacked: 0, // total packed size of all files

    // Add an entry, updating the counts and sizes.
    add: function(nSize, nPacked, bDir) {
        if (bDir) {
            this.nDirs++;
        } else {
            this.nFiles++;
            this.nSize += nSize;
            this.nPacked += nPacked;
        }
    },

    // Return the contents according to what was found - "P%,F files,D dirs".
    contents: function() {
        var sContents = "";
        if (this.nSize != 0) {
            sContents = (this.nPacked / this.nSize * 100).toFixed(1) + "%";
        }
        if (this.nFiles != 0) {
            sContents = sContents.append(this.nFiles + (this.nFiles == 1 ? " file" : " files"));
        }
        if (this.nDirs != 0) {
            sContents = sContents.append(this.nDirs + (this.nDirs == 1 ? " dir" : " dirs"));
        }
        return sContents;
    }
}