JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / JU / Deflater.js
1 Clazz.declarePackage ("JU");\r
2 Clazz.load (["JU.ZStream"], "JU.Deflater", ["JU.Deflate"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.$finished = false;\r
5 Clazz.instantialize (this, arguments);\r
6 }, JU, "Deflater", JU.ZStream);\r
7 Clazz.defineMethod (c$, "init", \r
8 function (level, bits, nowrap) {\r
9 if (bits == 0) bits = 15;\r
10 this.$finished = false;\r
11 this.setAdler32 ();\r
12 this.dstate =  new JU.Deflate (this);\r
13 this.dstate.deflateInit2 (level, nowrap ? -bits : bits);\r
14 return this;\r
15 }, "~N,~N,~B");\r
16 Clazz.overrideMethod (c$, "deflate", \r
17 function (flush) {\r
18 if (this.dstate == null) {\r
19 return -2;\r
20 }var ret = this.dstate.deflate (flush);\r
21 if (ret == 1) this.$finished = true;\r
22 return ret;\r
23 }, "~N");\r
24 Clazz.overrideMethod (c$, "end", \r
25 function () {\r
26 this.$finished = true;\r
27 if (this.dstate == null) return -2;\r
28 var ret = this.dstate.deflateEnd ();\r
29 this.dstate = null;\r
30 this.free ();\r
31 return ret;\r
32 });\r
33 Clazz.defineMethod (c$, "params", \r
34 function (level, strategy) {\r
35 if (this.dstate == null) return -2;\r
36 return this.dstate.deflateParams (level, strategy);\r
37 }, "~N,~N");\r
38 Clazz.defineMethod (c$, "setDictionary", \r
39 function (dictionary, dictLength) {\r
40 if (this.dstate == null) return -2;\r
41 return this.dstate.deflateSetDictionary (dictionary, dictLength);\r
42 }, "~A,~N");\r
43 Clazz.overrideMethod (c$, "finished", \r
44 function () {\r
45 return this.$finished;\r
46 });\r
47 Clazz.defineMethod (c$, "finish", \r
48 function () {\r
49 });\r
50 Clazz.defineMethod (c$, "getBytesRead", \r
51 function () {\r
52 return this.dstate.getBytesRead ();\r
53 });\r
54 Clazz.defineMethod (c$, "getBytesWritten", \r
55 function () {\r
56 return this.dstate.getBytesWritten ();\r
57 });\r
58 Clazz.defineStatics (c$,\r
59 "MAX_WBITS", 15,\r
60 "Z_STREAM_END", 1,\r
61 "$Z_STREAM_ERROR", -2);\r
62 });\r