~gandalfn/pantheon-debian/gtk+3.0

« back to all changes in this revision

Viewing changes to debian/missing-sources/zlib.js-0.1.6/src/gzip.js

  • Committer: gandalfn at club-internet
  • Date: 2015-08-20 09:24:34 UTC
  • Revision ID: gandalfn@club-internet.fr-20150820092434-obsec9i2cezvyyt6
Initial commit:

Release 3.14.5-1.1
  * debian/patches/ubuntu_gtk_custom_menu_items.patch:
    -  Add UbuntuMenuItemFactory
  * disable check on build package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @fileoverview GZIP (RFC1952) 実装.
 
3
 */
 
4
goog.provide('Zlib.Gzip');
 
5
 
 
6
goog.require('USE_TYPEDARRAY');
 
7
goog.require('Zlib.CRC32');
 
8
goog.require('Zlib.RawDeflate');
 
9
 
 
10
goog.scope(function() {
 
11
 
 
12
/**
 
13
 * @constructor
 
14
 * @param {!(Array|Uint8Array)} input input buffer.
 
15
 * @param {Object=} opt_params option parameters.
 
16
 */
 
17
Zlib.Gzip = function(input, opt_params) {
 
18
  /** @type {!(Array.<number>|Uint8Array)} input buffer. */
 
19
  this.input = input;
 
20
  /** @type {number} input buffer pointer. */
 
21
  this.ip = 0;
 
22
  /** @type {!(Array.<number>|Uint8Array)} output buffer. */
 
23
  this.output;
 
24
  /** @type {number} output buffer. */
 
25
  this.op = 0;
 
26
  /** @type {!Object} flags option flags. */
 
27
  this.flags = {};
 
28
  /** @type {!string} filename. */
 
29
  this.filename;
 
30
  /** @type {!string} comment. */
 
31
  this.comment;
 
32
  /** @type {!Object} deflate options. */
 
33
  this.deflateOptions;
 
34
 
 
35
  // option parameters
 
36
  if (opt_params) {
 
37
    if (opt_params['flags']) {
 
38
      this.flags = opt_params['flags'];
 
39
    }
 
40
    if (typeof opt_params['filename'] === 'string') {
 
41
      this.filename = opt_params['filename'];
 
42
    }
 
43
    if (typeof opt_params['comment'] === 'string') {
 
44
      this.comment = opt_params['comment'];
 
45
    }
 
46
    if (opt_params['deflateOptions']) {
 
47
      this.deflateOptions = opt_params['deflateOptions'];
 
48
    }
 
49
  }
 
50
 
 
51
  if (!this.deflateOptions) {
 
52
    this.deflateOptions = {};
 
53
  }
 
54
};
 
55
 
 
56
/**
 
57
 * @type {number}
 
58
 * @const
 
59
 */
 
60
Zlib.Gzip.DefaultBufferSize = 0x8000;
 
61
 
 
62
/**
 
63
 * encode gzip members.
 
64
 * @return {!(Array|Uint8Array)} gzip binary array.
 
65
 */
 
66
Zlib.Gzip.prototype.compress = function() {
 
67
  /** @type {number} flags. */
 
68
  var flg;
 
69
  /** @type {number} modification time. */
 
70
  var mtime;
 
71
  /** @type {number} CRC-16 value for FHCRC flag. */
 
72
  var crc16;
 
73
  /** @type {number} CRC-32 value for verification. */
 
74
  var crc32;
 
75
  /** @type {!Zlib.RawDeflate} raw deflate object. */
 
76
  var rawdeflate;
 
77
  /** @type {number} character code */
 
78
  var c;
 
79
  /** @type {number} loop counter. */
 
80
  var i;
 
81
  /** @type {number} loop limiter. */
 
82
  var il;
 
83
  /** @type {!(Array|Uint8Array)} output buffer. */
 
84
  var output =
 
85
    new (USE_TYPEDARRAY ? Uint8Array : Array)(Zlib.Gzip.DefaultBufferSize);
 
86
  /** @type {number} output buffer pointer. */
 
87
  var op = 0;
 
88
 
 
89
  var input = this.input;
 
90
  var ip = this.ip;
 
91
  var filename = this.filename;
 
92
  var comment = this.comment;
 
93
 
 
94
  // check signature
 
95
  output[op++] = 0x1f;
 
96
  output[op++] = 0x8b;
 
97
 
 
98
  // check compression method
 
99
  output[op++] = 8; /* XXX: use Zlib const */
 
100
 
 
101
  // flags
 
102
  flg = 0;
 
103
  if (this.flags['fname'])    flg |= Zlib.Gzip.FlagsMask.FNAME;
 
104
  if (this.flags['fcomment']) flg |= Zlib.Gzip.FlagsMask.FCOMMENT;
 
105
  if (this.flags['fhcrc'])    flg |= Zlib.Gzip.FlagsMask.FHCRC;
 
106
  // XXX: FTEXT
 
107
  // XXX: FEXTRA
 
108
  output[op++] = flg;
 
109
 
 
110
  // modification time
 
111
  mtime = (Date.now ? Date.now() : +new Date()) / 1000 | 0;
 
112
  output[op++] = mtime        & 0xff;
 
113
  output[op++] = mtime >>>  8 & 0xff;
 
114
  output[op++] = mtime >>> 16 & 0xff;
 
115
  output[op++] = mtime >>> 24 & 0xff;
 
116
 
 
117
  // extra flags
 
118
  output[op++] = 0;
 
119
 
 
120
  // operating system
 
121
  output[op++] = Zlib.Gzip.OperatingSystem.UNKNOWN;
 
122
 
 
123
  // extra
 
124
  /* NOP */
 
125
 
 
126
  // fname
 
127
  if (this.flags['fname'] !== void 0) {
 
128
    for (i = 0, il = filename.length; i < il; ++i) {
 
129
      c = filename.charCodeAt(i);
 
130
      if (c > 0xff) { output[op++] = (c >>> 8) & 0xff; }
 
131
      output[op++] = c & 0xff;
 
132
    }
 
133
    output[op++] = 0; // null termination
 
134
  }
 
135
 
 
136
  // fcomment
 
137
  if (this.flags['comment']) {
 
138
    for (i = 0, il = comment.length; i < il; ++i) {
 
139
      c = comment.charCodeAt(i);
 
140
      if (c > 0xff) { output[op++] = (c >>> 8) & 0xff; }
 
141
      output[op++] = c & 0xff;
 
142
    }
 
143
    output[op++] = 0; // null termination
 
144
  }
 
145
 
 
146
  // fhcrc
 
147
  if (this.flags['fhcrc']) {
 
148
    crc16 = Zlib.CRC32.calc(output, 0, op) & 0xffff;
 
149
    output[op++] = (crc16      ) & 0xff;
 
150
    output[op++] = (crc16 >>> 8) & 0xff;
 
151
  }
 
152
 
 
153
  // add compress option
 
154
  this.deflateOptions['outputBuffer'] = output;
 
155
  this.deflateOptions['outputIndex'] = op;
 
156
 
 
157
  // compress
 
158
  rawdeflate = new Zlib.RawDeflate(input, this.deflateOptions);
 
159
  output = rawdeflate.compress();
 
160
  op = rawdeflate.op;
 
161
 
 
162
  // expand buffer
 
163
  if (USE_TYPEDARRAY) {
 
164
    if (op + 8 > output.buffer.byteLength) {
 
165
      this.output = new Uint8Array(op + 8);
 
166
      this.output.set(new Uint8Array(output.buffer));
 
167
      output = this.output;
 
168
    } else {
 
169
      output = new Uint8Array(output.buffer);
 
170
    }
 
171
  }
 
172
 
 
173
  // crc32
 
174
  crc32 = Zlib.CRC32.calc(input);
 
175
  output[op++] = (crc32       ) & 0xff;
 
176
  output[op++] = (crc32 >>>  8) & 0xff;
 
177
  output[op++] = (crc32 >>> 16) & 0xff;
 
178
  output[op++] = (crc32 >>> 24) & 0xff;
 
179
 
 
180
  // input size
 
181
  il = input.length;
 
182
  output[op++] = (il       ) & 0xff;
 
183
  output[op++] = (il >>>  8) & 0xff;
 
184
  output[op++] = (il >>> 16) & 0xff;
 
185
  output[op++] = (il >>> 24) & 0xff;
 
186
 
 
187
  this.ip = ip;
 
188
 
 
189
  if (USE_TYPEDARRAY && op < output.length) {
 
190
    this.output = output = output.subarray(0, op);
 
191
  }
 
192
 
 
193
  return output;
 
194
};
 
195
 
 
196
/** @enum {number} */
 
197
Zlib.Gzip.OperatingSystem = {
 
198
  FAT: 0,
 
199
  AMIGA: 1,
 
200
  VMS: 2,
 
201
  UNIX: 3,
 
202
  VM_CMS: 4,
 
203
  ATARI_TOS: 5,
 
204
  HPFS: 6,
 
205
  MACINTOSH: 7,
 
206
  Z_SYSTEM: 8,
 
207
  CP_M: 9,
 
208
  TOPS_20: 10,
 
209
  NTFS: 11,
 
210
  QDOS: 12,
 
211
  ACORN_RISCOS: 13,
 
212
  UNKNOWN: 255
 
213
};
 
214
 
 
215
/** @enum {number} */
 
216
Zlib.Gzip.FlagsMask = {
 
217
  FTEXT: 0x01,
 
218
  FHCRC: 0x02,
 
219
  FEXTRA: 0x04,
 
220
  FNAME: 0x08,
 
221
  FCOMMENT: 0x10
 
222
};
 
223
 
 
224
});
 
225
/* vim:set expandtab ts=2 sw=2 tw=80: */