-
Notifications
You must be signed in to change notification settings - Fork 24
/
tar.html
75 lines (63 loc) · 1.81 KB
/
tar.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<script src="https://raw.github.com/vjeux/jDataView/master/jquery/jquery-1.7.1-binary-ajax.js"></script>
<script src="https://raw.github.com/vjeux/jDataView/master/src/jdataview.js"></script>
<script src="../../src/jparser.js"></script>
<style>
textarea { width: 80%; height: 300px; }
</style>
<p>Content of the file <a href="jquery.tar">jquery.tar</a></p>
<script>
function untar(view) {
var parser = new jParser(view, {
oct: function (size) {
return parseInt(this.parse(['string', size]), 8);
},
string0: function (size) {
return this.parse(['string', size]).replace(/\0+$/, '');
},
padding: ['skip', function () {
return (512 - (this.tell() % 512)) % 512;
}],
block: function (type) {
var res = [];
while (this.tell() < this.view.byteLength) {
res.push(this.parse(type));
}
return res;
},
file: {
name: ['string0', 100],
mode: ['oct', 8],
owner: ['oct', 8],
group: ['oct', 8],
size: ['oct', 12],
modtime: ['oct', 12],
checksum: ['oct', 8],
link: ['oct', 1],
name_linked: ['string0', 100],
ustar: ['string', 6],
ustar_version: ['oct', 2],
owner_name: ['string0', 32],
group_name: ['string0', 32],
device: ['array', ['oct', 8], 2],
name_prefix: ['string0', 155],
padding1: 'padding',
content: ['string', function () { return this.current.size; }],
padding2: 'padding'
},
all: ['block', 'file']
});
var files = parser.parse('all');
// Display the files
for (var i = 0; i < files.length; ++i) {
var file = files[i];
var content = file.content;
file.content = null; // Just for the display
$('body').append($('<pre></pre>').html(JSON.stringify(file, null, ' ')));
if (file.size) {
$('body').append($('<textarea></textarea>').val(content));
}
}
}
// Download the file
$.get('jquery.tar', untar, 'dataview');
</script>