1
0
mirror of synced 2025-02-20 20:21:24 +01:00

Merge branch 'tlwr-filedownload'

This commit is contained in:
n1474335 2017-03-21 23:07:54 +00:00
commit 45640f2f2e
2 changed files with 35 additions and 13 deletions

View File

@ -1028,20 +1028,37 @@ var Utils = {
};
var formatFile = function(file, i) {
var blob = new Blob(
[new Uint8Array(file.bytes)],
{type: "octet/stream"}
);
var blobUrl = URL.createObjectURL(blob);
var downloadAnchorElem = "<a href='" + blobUrl + "' " +
"title='Download " + Utils.escapeHtml(file.fileName) + "' " +
"download='" + Utils.escapeHtml(file.fileName) + "'>\u21B4</a>";
var expandFileContentsElem = "<a href='#collapse" + i + "' " +
"class='collapsed' " +
"data-toggle='collapse' " +
"aria-expanded='true' " +
"aria-controls='collapse" + i + "' " +
"title=\"Show/hide contents of '" + Utils.escapeHtml(file.fileName) + "'\">&#x1F50D</a>";
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' " +
"href='#collapse" + i + "' " +
"aria-expanded='true' aria-controls='collapse" + i +"'>" +
file.fileName +
"<div>" +
Utils.escapeHtml(file.fileName) +
" " + expandFileContentsElem +
" " + downloadAnchorElem +
"<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>" +
"</div>" +
"</h4>" +
"</div>" +
"<div id='collapse" + i + "' class='panel-collapse collapse' " +

View File

@ -309,9 +309,8 @@ var Compress = {
files = [];
filenames.forEach(function(fileName) {
var contents = unzip.decompress(fileName);
contents = Utils.byteArrayToUtf8(contents);
var bytes = unzip.decompress(fileName);
var contents = Utils.byteArrayToUtf8(bytes);
var file = {
fileName: fileName,
@ -320,6 +319,7 @@ var Compress = {
var isDir = contents.length === 0 && fileName.endsWith("/");
if (!isDir) {
file.bytes = bytes;
file.contents = contents;
}
@ -477,6 +477,13 @@ var Compress = {
this.position = 0;
};
Stream.prototype.getBytes = function(bytesToGet) {
var newPosition = this.position + bytesToGet;
var bytes = this.bytes.slice(this.position, newPosition);
this.position = newPosition;
return bytes;
};
Stream.prototype.readString = function(numBytes) {
var result = "";
for (var i = this.position; i < this.position + numBytes; i++) {
@ -535,11 +542,9 @@ var Compress = {
endPosition += 512 - (file.size % 512);
}
file.contents = "";
while (stream.position < endPosition) {
file.contents += stream.readString(512);
}
file.bytes = stream.getBytes(file.size);
file.contents = Utils.byteArrayToUtf8(file.bytes);
stream.position = endPosition;
} else if (file.type === "5") {
// Directory
files.push(file);