Commit 1eb10be2 authored by OzzieIsaacs's avatar OzzieIsaacs

Code cosmetics comic reader

parent 90729de8
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
* Copyright(c) 2011 Google Inc. * Copyright(c) 2011 Google Inc.
*/ */
/* global bitjs */
var bitjs = bitjs || {}; var bitjs = bitjs || {};
bitjs.archive = bitjs.archive || {}; bitjs.archive = bitjs.archive || {};
...@@ -15,7 +17,7 @@ bitjs.archive = bitjs.archive || {}; ...@@ -15,7 +17,7 @@ bitjs.archive = bitjs.archive || {};
// =========================================================================== // ===========================================================================
// Stolen from Closure because it's the best way to do Java-like inheritance. // Stolen from Closure because it's the best way to do Java-like inheritance.
bitjs.base = function(me, optMethodName, var_args) { bitjs.base = function(me, optMethodName, varArgs) {
var caller = arguments.callee.caller; var caller = arguments.callee.caller;
if (caller.superClass_) { if (caller.superClass_) {
// This is a constructor. Call the superclass constructor. // This is a constructor. Call the superclass constructor.
...@@ -48,10 +50,10 @@ bitjs.archive = bitjs.archive || {}; ...@@ -48,10 +50,10 @@ bitjs.archive = bitjs.archive || {};
}; };
bitjs.inherits = function(childCtor, parentCtor) { bitjs.inherits = function(childCtor, parentCtor) {
/** @constructor */ /** @constructor */
function tempCtor() {}; function TempCtor() {}
tempCtor.prototype = parentCtor.prototype; TempCtor.prototype = parentCtor.prototype;
childCtor.superClass_ = parentCtor.prototype; childCtor.superClass_ = parentCtor.prototype;
childCtor.prototype = new tempCtor(); childCtor.prototype = new TempCtor();
childCtor.prototype.constructor = childCtor; childCtor.prototype.constructor = childCtor;
}; };
// =========================================================================== // ===========================================================================
...@@ -141,12 +143,12 @@ bitjs.archive = bitjs.archive || {}; ...@@ -141,12 +143,12 @@ bitjs.archive = bitjs.archive || {};
* Progress event. * Progress event.
*/ */
bitjs.archive.UnarchiveProgressEvent = function( bitjs.archive.UnarchiveProgressEvent = function(
currentFilename, currentFilename,
currentFileNumber, currentFileNumber,
currentBytesUnarchivedInFile, currentBytesUnarchivedInFile,
currentBytesUnarchived, currentBytesUnarchived,
totalUncompressedBytesInArchive, totalUncompressedBytesInArchive,
totalFilesInArchive) totalFilesInArchive)
{ {
bitjs.base(this, bitjs.archive.UnarchiveEvent.Type.PROGRESS); bitjs.base(this, bitjs.archive.UnarchiveEvent.Type.PROGRESS);
...@@ -296,7 +298,7 @@ bitjs.archive = bitjs.archive || {}; ...@@ -296,7 +298,7 @@ bitjs.archive = bitjs.archive || {};
}; };
this.worker_.onmessage = function(e) { this.worker_.onmessage = function(e) {
if (typeof e.data == "string") { if (typeof e.data === "string") {
// Just log any strings the workers pump our way. // Just log any strings the workers pump our way.
console.log(e.data); console.log(e.data);
} else { } else {
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
* Copyright(c) 2011 antimatter15 * Copyright(c) 2011 antimatter15
*/ */
/* global bitjs, Uint8Array */
var bitjs = bitjs || {}; var bitjs = bitjs || {};
bitjs.io = bitjs.io || {}; bitjs.io = bitjs.io || {};
...@@ -58,16 +60,16 @@ bitjs.io = bitjs.io || {}; ...@@ -58,16 +60,16 @@ bitjs.io = bitjs.io || {};
* @return {number} The peeked bits, as an unsigned number. * @return {number} The peeked bits, as an unsigned number.
*/ */
bitjs.io.BitStream.prototype.peekBitsLtr = function(n, movePointers) { bitjs.io.BitStream.prototype.peekBitsLtr = function(n, movePointers) {
if (n <= 0 || typeof n != typeof 1) { if (n <= 0 || typeof n !== typeof 1) {
return 0; return 0;
} }
movePointers = movePointers || false, var movePointers = movePointers || false;
bytePtr = this.bytePtr, var bytePtr = this.bytePtr;
bitPtr = this.bitPtr, var bitPtr = this.bitPtr;
result = 0, var result = 0;
bitsIn = 0, var bitsIn = 0;
bytes = this.bytes; var bytes = this.bytes;
// keep going until we have no more bits left to peek at // keep going until we have no more bits left to peek at
// TODO: Consider putting all bits from bytes we will need into a variable and then // TODO: Consider putting all bits from bytes we will need into a variable and then
...@@ -123,11 +125,11 @@ bitjs.io = bitjs.io || {}; ...@@ -123,11 +125,11 @@ bitjs.io = bitjs.io || {};
return 0; return 0;
} }
var movePointers = movePointers || false, var movePointers = movePointers || false;
bytePtr = this.bytePtr, var bytePtr = this.bytePtr;
bitPtr = this.bitPtr, var bitPtr = this.bitPtr;
result = 0, var result = 0;
bytes = this.bytes; var bytes = this.bytes;
// keep going until we have no more bits left to peek at // keep going until we have no more bits left to peek at
// TODO: Consider putting all bits from bytes we will need into a variable and then // TODO: Consider putting all bits from bytes we will need into a variable and then
...@@ -138,7 +140,7 @@ bitjs.io = bitjs.io || {}; ...@@ -138,7 +140,7 @@ bitjs.io = bitjs.io || {};
if (bytePtr >= bytes.length) { if (bytePtr >= bytes.length) {
throw "Error! Overflowed the bit stream! n=" + n + ", bytePtr=" + bytePtr + ", bytes.length=" + throw "Error! Overflowed the bit stream! n=" + n + ", bytePtr=" + bytePtr + ", bytes.length=" +
bytes.length + ", bitPtr=" + bitPtr; bytes.length + ", bitPtr=" + bitPtr;
return -1; // return -1;
} }
var numBitsLeftInThisByte = (8 - bitPtr); var numBitsLeftInThisByte = (8 - bitPtr);
...@@ -207,8 +209,8 @@ bitjs.io = bitjs.io || {}; ...@@ -207,8 +209,8 @@ bitjs.io = bitjs.io || {};
} }
movePointers = movePointers || false; movePointers = movePointers || false;
var bytePtr = this.bytePtr, var bytePtr = this.bytePtr;
bitPtr = this.bitPtr; // var bitPtr = this.bitPtr;
var result = this.bytes.subarray(bytePtr, bytePtr + n); var result = this.bytes.subarray(bytePtr, bytePtr + n);
...@@ -255,7 +257,7 @@ bitjs.io = bitjs.io || {}; ...@@ -255,7 +257,7 @@ bitjs.io = bitjs.io || {};
*/ */
bitjs.io.ByteStream.prototype.peekNumber = function(n) { bitjs.io.ByteStream.prototype.peekNumber = function(n) {
// TODO: return error if n would go past the end of the stream? // TODO: return error if n would go past the end of the stream?
if (n <= 0 || typeof n !== typeof 1){ if (n <= 0 || typeof n !== typeof 1) {
return -1; return -1;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* http://kthoom.googlecode.com/hg/docs/unrar.html * http://kthoom.googlecode.com/hg/docs/unrar.html
*/ */
/* global bitjs */ /* global bitjs, importScripts */
// This file expects to be invoked as a Worker (see onmessage below). // This file expects to be invoked as a Worker (see onmessage below).
importScripts("io.js"); importScripts("io.js");
...@@ -42,23 +42,23 @@ var postProgress = function() { ...@@ -42,23 +42,23 @@ var postProgress = function() {
// shows a byte value as its hex representation // shows a byte value as its hex representation
var nibble = "0123456789ABCDEF"; var nibble = "0123456789ABCDEF";
var byteValueToHexString = function(num) { var byteValueToHexString = function(num) {
return nibble[num>>4] + nibble[num&0xF]; return nibble[num>>4] + nibble[num & 0xF];
}; };
var twoByteValueToHexString = function(num) { var twoByteValueToHexString = function(num) {
return nibble[(num>>12)&0xF] + nibble[(num>>8)&0xF] + nibble[(num>>4)&0xF] + nibble[num&0xF]; return nibble[(num>>12) & 0xF] + nibble[(num>>8) & 0xF] + nibble[(num>>4) & 0xF] + nibble[num & 0xF];
}; };
// Volume Types // Volume Types
var MARK_HEAD = 0x72, // MARK_HEAD = 0x72;
MAIN_HEAD = 0x73, var MAIN_HEAD = 0x73,
FILE_HEAD = 0x74, FILE_HEAD = 0x74,
COMM_HEAD = 0x75, // COMM_HEAD = 0x75,
AV_HEAD = 0x76, // AV_HEAD = 0x76,
SUB_HEAD = 0x77, // SUB_HEAD = 0x77,
PROTECT_HEAD = 0x78, // PROTECT_HEAD = 0x78,
SIGN_HEAD = 0x79, // SIGN_HEAD = 0x79,
NEWSUB_HEAD = 0x7a, // NEWSUB_HEAD = 0x7a,
ENDARC_HEAD = 0x7b; ENDARC_HEAD = 0x7b;
// bstream is a bit stream // bstream is a bit stream
...@@ -66,7 +66,7 @@ var RarVolumeHeader = function(bstream) { ...@@ -66,7 +66,7 @@ var RarVolumeHeader = function(bstream) {
var headPos = bstream.bytePtr; var headPos = bstream.bytePtr;
// byte 1,2 // byte 1,2
info("Rar Volume Header @"+bstream.bytePtr); info("Rar Volume Header @" + bstream.bytePtr);
this.crc = bstream.readBits(16); this.crc = bstream.readBits(16);
info(" crc=" + this.crc); info(" crc=" + this.crc);
...@@ -147,7 +147,7 @@ var RarVolumeHeader = function(bstream) { ...@@ -147,7 +147,7 @@ var RarVolumeHeader = function(bstream) {
this.HighPackSize = 0; this.HighPackSize = 0;
this.HighUnpSize = 0; this.HighUnpSize = 0;
if (this.unpackedSize == 0xffffffff) { if (this.unpackedSize == 0xffffffff) {
this.HighUnpSize = 0x7fffffff this.HighUnpSize = 0x7fffffff;
this.unpackedSize = 0xffffffff; this.unpackedSize = 0xffffffff;
} }
} }
...@@ -160,7 +160,7 @@ var RarVolumeHeader = function(bstream) { ...@@ -160,7 +160,7 @@ var RarVolumeHeader = function(bstream) {
// read in filename // read in filename
this.filename = bstream.readBytes(this.nameSize); this.filename = bstream.readBytes(this.nameSize);
for (var _i = 0, _s = ''; _i < this.filename.length; _i++) { for (var _i = 0, _s = ""; _i < this.filename.length ; _i++) {
_s += String.fromCharCode(this.filename[_i]); _s += String.fromCharCode(this.filename[_i]);
} }
...@@ -177,14 +177,16 @@ var RarVolumeHeader = function(bstream) { ...@@ -177,14 +177,16 @@ var RarVolumeHeader = function(bstream) {
// this is adapted straight out of arcread.cpp, Archive::ReadHeader() // this is adapted straight out of arcread.cpp, Archive::ReadHeader()
for (var I = 0; I < 4; ++I) { for (var I = 0; I < 4; ++I) {
var rmode = extTimeFlags >> ((3-I)*4); var rmode = extTimeFlags >> ((3 - I) * 4);
if ((rmode & 8)==0) if ((rmode & 8)==0)
continue; continue;
if (I!=0) if (I!=0) {
bstream.readBits(16); bstream.readBits(16);
var count = (rmode&3); }
for (var J = 0; J < count; ++J) var count = (rmode & 3);
bstream.readBits(8); for (var J = 0; J < count; ++J) {
bstream.readBits(8);
}
} }
} }
...@@ -193,7 +195,7 @@ var RarVolumeHeader = function(bstream) { ...@@ -193,7 +195,7 @@ var RarVolumeHeader = function(bstream) {
} }
while(headPos + this.headSize > bstream.bytePtr) bstream.readBits(1); while (headPos + this.headSize > bstream.bytePtr) bstream.readBits(1);
info("Found FILE_HEAD with packSize=" + this.packSize + ", unpackedSize= " + this.unpackedSize + ", hostOS=" + this.hostOS + ", unpVer=" + this.unpVer + ", method=" + this.method + ", filename=" + this.filename); info("Found FILE_HEAD with packSize=" + this.packSize + ", unpackedSize= " + this.unpackedSize + ", hostOS=" + this.hostOS + ", unpVer=" + this.unpVer + ", method=" + this.method + ", filename=" + this.filename);
...@@ -206,24 +208,24 @@ var RarVolumeHeader = function(bstream) { ...@@ -206,24 +208,24 @@ var RarVolumeHeader = function(bstream) {
} }
}; };
var BLOCK_LZ = 0, var BLOCK_LZ = 0;
BLOCK_PPM = 1; // BLOCK_PPM = 1;
var rLDecode = [0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224], var rLDecode = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224],
rLBits = [0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5], rLBits = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],
rDBitLengthCounts = [4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,14,0,12], rDBitLengthCounts = [4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 14, 0, 12],
rSDDecode = [0,4,8,16,32,64,128,192], rSDDecode = [0, 4, 8, 16, 32, 64, 128, 192],
rSDBits = [2,2,3, 4, 5, 6, 6, 6]; rSDBits = [2,2,3, 4, 5, 6, 6, 6];
var rDDecode = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, var rDDecode = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32,
48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072,
4096, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304, 4096, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304,
131072, 196608, 262144, 327680, 393216, 458752, 524288, 589824, 131072, 196608, 262144, 327680, 393216, 458752, 524288, 589824,
655360, 720896, 786432, 851968, 917504, 983040]; 655360, 720896, 786432, 851968, 917504, 983040];
var rDBits = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, var rDBits = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5,
5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14,
15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16]; 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16];
var rLOW_DIST_REP_COUNT = 16; var rLOW_DIST_REP_COUNT = 16;
...@@ -232,35 +234,35 @@ var rNC = 299, ...@@ -232,35 +234,35 @@ var rNC = 299,
rLDC = 17, rLDC = 17,
rRC = 28, rRC = 28,
rBC = 20, rBC = 20,
rHUFF_TABLE_SIZE = (rNC+rDC+rRC+rLDC); rHUFF_TABLE_SIZE = (rNC + rDC + rRC + rLDC);
var UnpBlockType = BLOCK_LZ; var UnpBlockType = BLOCK_LZ;
var UnpOldTable = new Array(rHUFF_TABLE_SIZE); var UnpOldTable = new Array(rHUFF_TABLE_SIZE);
var BD = { //bitdecode var BD = { //bitdecode
DecodeLen: new Array(16), DecodeLen: new Array(16),
DecodePos: new Array(16), DecodePos: new Array(16),
DecodeNum: new Array(rBC) DecodeNum: new Array(rBC)
}; };
var LD = { //litdecode var LD = { //litdecode
DecodeLen: new Array(16), DecodeLen: new Array(16),
DecodePos: new Array(16), DecodePos: new Array(16),
DecodeNum: new Array(rNC) DecodeNum: new Array(rNC)
}; };
var DD = { //distdecode var DD = { //distdecode
DecodeLen: new Array(16), DecodeLen: new Array(16),
DecodePos: new Array(16), DecodePos: new Array(16),
DecodeNum: new Array(rDC) DecodeNum: new Array(rDC)
}; };
var LDD = { //low dist decode var LDD = { //low dist decode
DecodeLen: new Array(16), DecodeLen: new Array(16),
DecodePos: new Array(16), DecodePos: new Array(16),
DecodeNum: new Array(rLDC) DecodeNum: new Array(rLDC)
}; };
var RD = { //rep decode var RD = { //rep decode
DecodeLen: new Array(16), DecodeLen: new Array(16),
DecodePos: new Array(16), DecodePos: new Array(16),
DecodeNum: new Array(rRC) DecodeNum: new Array(rRC)
}; };
var rBuffer; var rBuffer;
...@@ -742,7 +744,7 @@ function unpack(v) { ...@@ -742,7 +744,7 @@ function unpack(v) {
rBuffer = new bitjs.io.ByteBuffer(v.header.unpackedSize); rBuffer = new bitjs.io.ByteBuffer(v.header.unpackedSize);
info("Unpacking "+v.filename+" RAR v"+Ver); info("Unpacking " + v.filename+" RAR v" + Ver);
switch(Ver) { switch(Ver) {
case 15: // rar 1.5 compression case 15: // rar 1.5 compression
...@@ -816,7 +818,7 @@ var unrar = function(arrayBuffer) { ...@@ -816,7 +818,7 @@ var unrar = function(arrayBuffer) {
postMessage(new bitjs.archive.UnarchiveStartEvent()); postMessage(new bitjs.archive.UnarchiveStartEvent());
var bstream = new bitjs.io.BitStream(arrayBuffer, false /* rtl */); var bstream = new bitjs.io.BitStream(arrayBuffer, false /* rtl */);
var header = new RarVolumeHeader(bstream); var header = new RarVolumeHeader(bstream);
if (header.crc == 0x6152 && if (header.crc == 0x6152 &&
header.headType == 0x72 && header.headType == 0x72 &&
......
...@@ -7,11 +7,10 @@ ...@@ -7,11 +7,10 @@
* *
* TAR format: http://www.gnu.org/software/automake/manual/tar/Standard.html * TAR format: http://www.gnu.org/software/automake/manual/tar/Standard.html
*/ */
/* global bitjs */
// This file expects to be invoked as a Worker (see onmessage below). // This file expects to be invoked as a Worker (see onmessage below).
importScripts("io.js"); importScripts('io.js');
importScripts("archive.js"); importScripts('archive.js');
// Progress variables. // Progress variables.
var currentFilename = ""; var currentFilename = "";
...@@ -23,147 +22,147 @@ var totalFilesInArchive = 0; ...@@ -23,147 +22,147 @@ var totalFilesInArchive = 0;
// Helper functions. // Helper functions.
var info = function(str) { var info = function(str) {
postMessage(new bitjs.archive.UnarchiveInfoEvent(str)); postMessage(new bitjs.archive.UnarchiveInfoEvent(str));
}; };
var err = function(str) { var err = function(str) {
postMessage(new bitjs.archive.UnarchiveErrorEvent(str)); postMessage(new bitjs.archive.UnarchiveErrorEvent(str));
}; };
var postProgress = function() { var postProgress = function() {
postMessage(new bitjs.archive.UnarchiveProgressEvent( postMessage(new bitjs.archive.UnarchiveProgressEvent(
currentFilename, currentFilename,
currentFileNumber, currentFileNumber,
currentBytesUnarchivedInFile, currentBytesUnarchivedInFile,
currentBytesUnarchived, currentBytesUnarchived,
totalUncompressedBytesInArchive, totalUncompressedBytesInArchive,
totalFilesInArchive)); totalFilesInArchive));
}; };
// Removes all characters from the first zero-byte in the string onwards. // Removes all characters from the first zero-byte in the string onwards.
var readCleanString = function(bstr, numBytes) { var readCleanString = function(bstr, numBytes) {
var str = bstr.readString(numBytes); var str = bstr.readString(numBytes);
var zIndex = str.indexOf(String.fromCharCode(0)); var zIndex = str.indexOf(String.fromCharCode(0));
return zIndex !== -1 ? str.substr(0, zIndex) : str; return zIndex != -1 ? str.substr(0, zIndex) : str;
}; };
// takes a ByteStream and parses out the local file information // takes a ByteStream and parses out the local file information
var TarLocalFile = function(bstream) { var TarLocalFile = function(bstream) {
this.isValid = false; this.isValid = false;
// Read in the header block // Read in the header block
this.name = readCleanString(bstream, 100); this.name = readCleanString(bstream, 100);
this.mode = readCleanString(bstream, 8); this.mode = readCleanString(bstream, 8);
this.uid = readCleanString(bstream, 8); this.uid = readCleanString(bstream, 8);
this.gid = readCleanString(bstream, 8); this.gid = readCleanString(bstream, 8);
this.size = parseInt(readCleanString(bstream, 12), 8); this.size = parseInt(readCleanString(bstream, 12), 8);
this.mtime = readCleanString(bstream, 12); this.mtime = readCleanString(bstream, 12);
this.chksum = readCleanString(bstream, 8); this.chksum = readCleanString(bstream, 8);
this.typeflag = readCleanString(bstream, 1); this.typeflag = readCleanString(bstream, 1);
this.linkname = readCleanString(bstream, 100); this.linkname = readCleanString(bstream, 100);
this.maybeMagic = readCleanString(bstream, 6); this.maybeMagic = readCleanString(bstream, 6);
if (this.maybeMagic === "ustar") { if (this.maybeMagic == "ustar") {
this.version = readCleanString(bstream, 2); this.version = readCleanString(bstream, 2);
this.uname = readCleanString(bstream, 32); this.uname = readCleanString(bstream, 32);
this.gname = readCleanString(bstream, 32); this.gname = readCleanString(bstream, 32);
this.devmajor = readCleanString(bstream, 8); this.devmajor = readCleanString(bstream, 8);
this.devminor = readCleanString(bstream, 8); this.devminor = readCleanString(bstream, 8);
this.prefix = readCleanString(bstream, 155); this.prefix = readCleanString(bstream, 155);
if (this.prefix.length) { if (this.prefix.length) {
this.name = this.prefix + this.name; this.name = this.prefix + this.name;
} }
bstream.readBytes(12); // 512 - 500 bstream.readBytes(12); // 512 - 500
} else { } else {
bstream.readBytes(255); // 512 - 257 bstream.readBytes(255); // 512 - 257
} }
// Done header, now rest of blocks are the file contents. // Done header, now rest of blocks are the file contents.
this.filename = this.name; this.filename = this.name;
this.fileData = null; this.fileData = null;
info("Untarring file '" + this.filename + "'"); info("Untarring file '" + this.filename + "'");
info(" size = " + this.size); info(" size = " + this.size);
info(" typeflag = " + this.typeflag); info(" typeflag = " + this.typeflag);
// A regular file. // A regular file.
if (this.typeflag === 0) { if (this.typeflag == 0) {
info(" This is a regular file."); info(" This is a regular file.");
var sizeInBytes = parseInt(this.size); var sizeInBytes = parseInt(this.size);
this.fileData = new Uint8Array(bstream.bytes.buffer, bstream.ptr, this.size); this.fileData = new Uint8Array(bstream.bytes.buffer, bstream.ptr, this.size);
if (this.name.length > 0 && this.size > 0 && this.fileData && this.fileData.buffer) { if (this.name.length > 0 && this.size > 0 && this.fileData && this.fileData.buffer) {
this.isValid = true; this.isValid = true;
} }
bstream.readBytes(this.size); bstream.readBytes(this.size);
// Round up to 512-byte blocks. // Round up to 512-byte blocks.
var remaining = 512 - this.size % 512; var remaining = 512 - this.size % 512;
if (remaining > 0 && remaining < 512) { if (remaining > 0 && remaining < 512) {
bstream.readBytes(remaining); bstream.readBytes(remaining);
} }
} else if (this.typeflag === 5) { } else if (this.typeflag == 5) {
info(" This is a directory."); info(" This is a directory.")
} }
}; };
// Takes an ArrayBuffer of a tar file in // Takes an ArrayBuffer of a tar file in
// returns null on error // returns null on error
// returns an array of DecompressedFile objects on success // returns an array of DecompressedFile objects on success
var untar = function(arrayBuffer) { var untar = function(arrayBuffer) {
currentFilename = ""; currentFilename = "";
currentFileNumber = 0; currentFileNumber = 0;
currentBytesUnarchivedInFile = 0; currentBytesUnarchivedInFile = 0;
currentBytesUnarchived = 0; currentBytesUnarchived = 0;
totalUncompressedBytesInArchive = 0; totalUncompressedBytesInArchive = 0;
totalFilesInArchive = 0; totalFilesInArchive = 0;
postMessage(new bitjs.archive.UnarchiveStartEvent()); postMessage(new bitjs.archive.UnarchiveStartEvent());
var bstream = new bitjs.io.ByteStream(arrayBuffer); var bstream = new bitjs.io.ByteStream(arrayBuffer);
var localFiles = []; var localFiles = [];
// While we don't encounter an empty block, keep making TarLocalFiles. // While we don't encounter an empty block, keep making TarLocalFiles.
while (bstream.peekNumber(4) !== 0) { while (bstream.peekNumber(4) != 0) {
var oneLocalFile = new TarLocalFile(bstream); var oneLocalFile = new TarLocalFile(bstream);
if (oneLocalFile && oneLocalFile.isValid) { if (oneLocalFile && oneLocalFile.isValid) {
localFiles.push(oneLocalFile); localFiles.push(oneLocalFile);
totalUncompressedBytesInArchive += oneLocalFile.size; totalUncompressedBytesInArchive += oneLocalFile.size;
} }
} }
totalFilesInArchive = localFiles.length; totalFilesInArchive = localFiles.length;
// got all local files, now sort them // got all local files, now sort them
localFiles.sort(function(a, b) { localFiles.sort(function(a,b) {
var aname = a.filename.toLowerCase(); var aname = a.filename.toLowerCase();
var bname = b.filename.toLowerCase(); var bname = b.filename.toLowerCase();
return aname > bname ? 1 : -1; return aname > bname ? 1 : -1;
}); });
// report # files and total length // report # files and total length
if (localFiles.length > 0) { if (localFiles.length > 0) {
postProgress(); postProgress();
} }
// now do the shipping of each file // now do the shipping of each file
for (var i = 0; i < localFiles.length; ++i) { for (var i = 0; i < localFiles.length; ++i) {
var localfile = localFiles[i]; var localfile = localFiles[i];
info("Sending file '" + localfile.filename + "' up"); info("Sending file '" + localfile.filename + "' up");
// update progress // update progress
currentFilename = localfile.filename; currentFilename = localfile.filename;
currentFileNumber = i; currentFileNumber = i;
currentBytesUnarchivedInFile = localfile.size; currentBytesUnarchivedInFile = localfile.size;
currentBytesUnarchived += localfile.size; currentBytesUnarchived += localfile.size;
postMessage(new bitjs.archive.UnarchiveExtractEvent(localfile)); postMessage(new bitjs.archive.UnarchiveExtractEvent(localfile));
postProgress();
}
postProgress(); postProgress();
}
postProgress();
postMessage(new bitjs.archive.UnarchiveFinishEvent()); postMessage(new bitjs.archive.UnarchiveFinishEvent());
}; };
// event.data.file has the ArrayBuffer. // event.data.file has the ArrayBuffer.
onmessage = function(event) { onmessage = function(event) {
var ab = event.data.file; var ab = event.data.file;
untar(ab); untar(ab);
}; };
This diff is collapsed.
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
</div> </div>
<button type="submit" name="submit" value="submit" class="btn btn-default">{{_('Save settings')}}</button> <button type="submit" name="submit" value="submit" class="btn btn-default">{{_('Save settings')}}</button>
<button type="submit" name="test" value="test" class="btn btn-default">{{_('Save settings and send Test E-Mail')}}</button> <button type="submit" name="test" value="test" class="btn btn-default">{{_('Save settings and send Test E-Mail')}}</button>
<a href="{{ url_for('admin') }}" class="btn btn-default">{{_('Back')}}</a> <a href="{{ url_for('admin') }}" id="back" class="btn btn-default">{{_('Back')}}</a>
</form> </form>
</div> </div>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<div class="row"> <div class="row">
{% for entry in random %} {% for entry in random %}
<div class="col-sm-3 col-lg-2 col-xs-6 book"> <div class="col-sm-3 col-lg-2 col-xs-6 book" id="books_rand">
<div class="cover"> <div class="cover">
<a href="{{ url_for('show_book', book_id=entry.id) }}" data-toggle="modal" data-target="#bookDetailsModal" data-remote="false"> <a href="{{ url_for('show_book', book_id=entry.id) }}" data-toggle="modal" data-target="#bookDetailsModal" data-remote="false">
{% if entry.has_cover %} {% if entry.has_cover %}
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<div class="row"> <div class="row">
{% if entries[0] %} {% if entries[0] %}
{% for entry in entries %} {% for entry in entries %}
<div class="col-sm-3 col-lg-2 col-xs-6 book"> <div class="col-sm-3 col-lg-2 col-xs-6 book" id="books">
<div class="cover"> <div class="cover">
<a href="{{ url_for('show_book', book_id=entry.id) }}" data-toggle="modal" data-target="#bookDetailsModal" data-remote="false"> <a href="{{ url_for('show_book', book_id=entry.id) }}" data-toggle="modal" data-target="#bookDetailsModal" data-remote="false">
{% if entry.has_cover %} {% if entry.has_cover %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment