This repository was archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathJSIL.IO.Compression.js
More file actions
158 lines (131 loc) · 5.19 KB
/
JSIL.IO.Compression.js
File metadata and controls
158 lines (131 loc) · 5.19 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"use strict";
if (typeof (JSIL) == "undefined")
throw new Error("JSIL.Core is required");
var $jsilcompression = JSIL.DeclareAssembly("JSIL.IO.Compression");
var $systemio = JSIL.GetAssembly("System.IO");
JSIL.ImplementExternals("System.IO.Compression.ZipArchive", function ($) {
$.Method({ Static: false, Public: true }, ".ctor",
new JSIL.MethodSignature(null, [$systemio.TypeRef("System.IO.Stream")], []),
function (stream) {
this._stream = stream;
this._zip = new JSZip(this._stream._buffer);
}
);
$.Method({ Static: false, Public: true }, ".ctor",
new JSIL.MethodSignature(null, [$systemio.TypeRef("System.IO.Stream"), $jsilcompression.TypeRef("System.IO.Compression.ZipArchiveMode")]),
function (stream, zipArchiveMode, leaveOpen) {
this._stream = stream;
this._zip = new JSZip(this._stream._buffer);
}
);
$.Method({ Static: false, Public: true }, ".ctor",
new JSIL.MethodSignature(null, [$systemio.TypeRef("System.IO.Stream"), $jsilcompression.TypeRef("System.IO.Compression.ZipArchiveMode"), $.Boolean]),
function (stream, zipArchiveMode, leaveOpen) {
this._stream = stream;
this._zip = new JSZip(this._stream._buffer);
}
);
$.Method({ Static: false, Public: true }, "CreateEntry",
new JSIL.MethodSignature($jsilcompression.TypeRef("System.IO.Compression.ZipArchiveEntry"), [$.String], []),
function (entryName) {
// FIXME: ZipArchive CreateEntry
}
);
$.Method({ Static: false, Public: true }, "Dispose",
new JSIL.MethodSignature(null, [], []),
function Dispose() {
// FIXME: ZipArchive Dispose
}
);
$.Method({ Static: false, Public: true }, "get_Entries",
new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.ObjectModel.ReadOnlyCollection`1", $jsilcompression.TypeRef("System.IO.Compression.ZipArchiveEntry")), [], []),
function get_Entries() {
if (this._entries === null) {
var tList = System.Collections.Generic.List$b1.Of(System.IO.Compression.ZipArchiveEntry.__Type__).__Type__;
var list = JSIL.CreateInstanceOfType(tList);
for (var entryName in this._zip.files) {
var entry = this._zip.file(entryName);
// Only add files
if (entry !== null && entry.dir === false) {
var tZipArchiveEntry = System.IO.Compression.ZipArchiveEntry.__Type__;
var zipArchiveEntry = JSIL.CreateInstanceOfType(tZipArchiveEntry, "$internalCtor", [entry]);
list.Add(zipArchiveEntry);
}
}
var tReadOnlyCollection = System.Collections.ObjectModel.ReadOnlyCollection$b1.Of(System.IO.Compression.ZipArchiveEntry.__Type__).__Type__;
this._entries = JSIL.CreateInstanceOfType(tReadOnlyCollection, "$listCtor", [list]);
}
return this._entries;
}
);
$.Method({ Static: false, Public: true }, "GetEntry",
new JSIL.MethodSignature($jsilcompression.TypeRef("System.IO.Compression.ZipArchiveEntry"), [$.String], []),
function GetEntry(entryName) {
var entry = this._zip.file(entryName);
// Only return files
if (entry !== null && entry.dir === false) {
var tZipArchiveEntry = System.IO.Compression.ZipArchiveEntry.__Type__;
var zipArchiveEntry = JSIL.CreateInstanceOfType(tZipArchiveEntry, "$internalCtor", [entry]);
return zipArchiveEntry;
} else {
// FIXME: Check the exception that's returned if an entry is not found
return null;
}
}
);
});
JSIL.ImplementExternals("System.IO.Compression.ZipArchiveEntry", function ($) {
$.RawMethod(false, "$internalCtor",
function internalCtor(entry) {
this._entry = entry;
// Cache this - data is overwritten when decompressed
this._compressedSize = entry._data._compressedSize;
this._uncompressedSize = entry._data._uncompressedSize;
}
);
$.Method({ Static: false, Public: true }, ".ctor",
new JSIL.MethodSignature(null, [], []),
function () {
// FIXME: Initialize ZipArchiveEntry?
}
);
$.Method({ Static: false, Public: true }, "Open",
new JSIL.MethodSignature($jsilcompression.TypeRef("System.IO.Stream"), [], []),
function () {
var array = this._entry.asUint8Array();
var stream = new System.IO.MemoryStream(array);
return stream;
}
);
$.Method({ Static: false, Public: true }, "Delete",
new JSIL.MethodSignature(null, [], []),
function () {
// FIXME: Delete ZipArchiveEntry
}
);
$.Method({ Static: false, Public: true }, "get_Name",
new JSIL.MethodSignature($.String, [], []),
function get_Name() {
var entryName = System.IO.Path.GetFileName(this._entry.name);
return entryName;
}
);
$.Method({ Static: false, Public: true }, "get_FullName",
new JSIL.MethodSignature($.String, [], []),
function get_FullName() {
return this._entry.name;
}
);
$.Method({ Static: false, Public: true }, "get_CompressedLength",
new JSIL.MethodSignature($.Int64, [], []),
function get_CompressedLength() {
return this._compressedSize;
}
);
$.Method({ Static: false, Public: true }, "get_Length",
new JSIL.MethodSignature($.Int64, [], []),
function get_Length() {
return this._uncompressedSize;
}
);
});