Initial functionality of untar

+ Added skeleton "Tar" operation with no functionality
+ Added intial functionality of "Untar"
+ Added a function in `Utils` `HTMLFormat` to generalize HTML generation
of files and folders (could later be used in Unzip).

I had a brief search for a small library for tar and untar operations,
however they were mostly for node (if anyone finds one we can drop in
that would be appreciated) or unmaintained. Luckily the tar spec is
relatively easy to understand just from Wikipedia.
This commit is contained in:
toby 2017-02-08 00:05:52 -05:00
parent 35d74980a1
commit e809deb914
4 changed files with 191 additions and 1 deletions

View file

@ -929,6 +929,65 @@ var Utils = {
},
/**
* Formats a list of files or directories.
*
* @param {File[]} files
* @returns {html}
*/
HTMLFiles: function(files){
var formatDirectory = function(file) {
var html = "<div class='panel panel-default'>" +
"<div class='panel-heading' role='tab'>" +
"<h4 class='panel-title'>" +
file.fileName +
// The following line is for formatting when HTML is stripped
"<span style='display: none'>\n0 bytes\n</span>" +
"</h4>" +
"</div>" +
"</div>";
return html;
};
var formatFile = function(file, i) {
var html = "<div class='panel panel-default'>" +
"<div class='panel-heading' role='tab' id='heading" + i + "'>" +
"<h4 class='panel-title'>" +
"<a class='collapsed' role='button' data-toggle='collapse' " +
"data-parent='#zip-accordion' href='#collapse" + i + "' " +
"aria-expanded='true' aria-controls='collapse" + i +"'>" +
file.fileName +
"<span class='pull-right'>" +
// These are for formatting when stripping HTML
"<span style='display: none'>\n</span>" +
file.size.toLocaleString() + " bytes" +
"<span style='display: none'>\n</span>" +
"</span>" +
"</a>" +
"</h4>" +
"</div>" +
"<div id='collapse" + i + "' class='panel-collapse collapse' " +
"role='tabpanel' aria-labelledby='heading" + i + "'>" +
"<div class='panel-body'>" +
"<pre><code>" + Utils.escapeHtml(file.contents) + "</pre></code></div>" +
"</div>" +
"</div>";
return html;
};
var Utils = this;
var html = "";
files.forEach(function(file, i) {
if(typeof file.contents !== "undefined") {
html += formatFile(file, i);
} else {
html += formatDirectory(file);
}
});
return html;
},
/**
* A mapping of names of delimiter characters to their symbols.
* @constant