@mehmetb/rollup-plugin-node-builtins 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -0
- package/dist/constants.js +474 -0
- package/dist/rollup-plugin-node-builtins.cjs.js +77 -0
- package/dist/rollup-plugin-node-builtins.es6.js +75 -0
- package/package.json +42 -0
- package/src/es6/assert.js +488 -0
- package/src/es6/console.js +13 -0
- package/src/es6/domain.js +100 -0
- package/src/es6/empty.js +1 -0
- package/src/es6/events.js +475 -0
- package/src/es6/http-lib/capability.js +52 -0
- package/src/es6/http-lib/request.js +278 -0
- package/src/es6/http-lib/response.js +185 -0
- package/src/es6/http-lib/to-arraybuffer.js +30 -0
- package/src/es6/http.js +167 -0
- package/src/es6/inherits.js +25 -0
- package/src/es6/os.js +113 -0
- package/src/es6/path.js +234 -0
- package/src/es6/punycode.js +475 -0
- package/src/es6/qs.js +147 -0
- package/src/es6/readable-stream/buffer-list.js +59 -0
- package/src/es6/readable-stream/duplex.js +45 -0
- package/src/es6/readable-stream/passthrough.js +15 -0
- package/src/es6/readable-stream/readable.js +896 -0
- package/src/es6/readable-stream/transform.js +174 -0
- package/src/es6/readable-stream/writable.js +483 -0
- package/src/es6/setimmediate.js +185 -0
- package/src/es6/stream.js +110 -0
- package/src/es6/string-decoder.js +220 -0
- package/src/es6/timers.js +76 -0
- package/src/es6/tty.js +20 -0
- package/src/es6/url.js +745 -0
- package/src/es6/util.js +598 -0
- package/src/es6/vm.js +202 -0
- package/src/es6/zlib-lib/LICENSE +21 -0
- package/src/es6/zlib-lib/adler32.js +31 -0
- package/src/es6/zlib-lib/binding.js +269 -0
- package/src/es6/zlib-lib/crc32.js +40 -0
- package/src/es6/zlib-lib/deflate.js +1862 -0
- package/src/es6/zlib-lib/inffast.js +325 -0
- package/src/es6/zlib-lib/inflate.js +1650 -0
- package/src/es6/zlib-lib/inftrees.js +329 -0
- package/src/es6/zlib-lib/messages.js +11 -0
- package/src/es6/zlib-lib/trees.js +1220 -0
- package/src/es6/zlib-lib/utils.js +73 -0
- package/src/es6/zlib-lib/zstream.js +28 -0
- package/src/es6/zlib.js +635 -0
- package/src/index.js +73 -0
package/src/es6/vm.js
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
/*
|
2
|
+
from https://github.com/substack/vm-browserify/blob/bfd7c5f59edec856dc7efe0b77a4f6b2fa20f226/index.js
|
3
|
+
|
4
|
+
MIT license no Copyright holder mentioned
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
function Object_keys(obj) {
|
9
|
+
if (Object.keys) return Object.keys(obj)
|
10
|
+
else {
|
11
|
+
var res = [];
|
12
|
+
for (var key in obj) res.push(key)
|
13
|
+
return res;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
function forEach(xs, fn) {
|
18
|
+
if (xs.forEach) return xs.forEach(fn)
|
19
|
+
else
|
20
|
+
for (var i = 0; i < xs.length; i++) {
|
21
|
+
fn(xs[i], i, xs);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
var _defineProp;
|
25
|
+
|
26
|
+
function defineProp(obj, name, value) {
|
27
|
+
if (typeof _defineProp !== 'function') {
|
28
|
+
_defineProp = createDefineProp;
|
29
|
+
}
|
30
|
+
_defineProp(obj, name, value);
|
31
|
+
}
|
32
|
+
|
33
|
+
function createDefineProp() {
|
34
|
+
try {
|
35
|
+
Object.defineProperty({}, '_', {});
|
36
|
+
return function(obj, name, value) {
|
37
|
+
Object.defineProperty(obj, name, {
|
38
|
+
writable: true,
|
39
|
+
enumerable: false,
|
40
|
+
configurable: true,
|
41
|
+
value: value
|
42
|
+
})
|
43
|
+
};
|
44
|
+
} catch (e) {
|
45
|
+
return function(obj, name, value) {
|
46
|
+
obj[name] = value;
|
47
|
+
};
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
var globals = ['Array', 'Boolean', 'Date', 'Error', 'EvalError', 'Function',
|
52
|
+
'Infinity', 'JSON', 'Math', 'NaN', 'Number', 'Object', 'RangeError',
|
53
|
+
'ReferenceError', 'RegExp', 'String', 'SyntaxError', 'TypeError', 'URIError',
|
54
|
+
'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'escape',
|
55
|
+
'eval', 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'undefined', 'unescape'
|
56
|
+
];
|
57
|
+
|
58
|
+
function Context() {}
|
59
|
+
Context.prototype = {};
|
60
|
+
|
61
|
+
export function Script(code) {
|
62
|
+
if (!(this instanceof Script)) return new Script(code);
|
63
|
+
this.code = code;
|
64
|
+
}
|
65
|
+
function otherRunInContext(code, context) {
|
66
|
+
var args = Object_keys(global);
|
67
|
+
args.push('with (this.__ctx__){return eval(this.__code__)}');
|
68
|
+
var fn = Function.apply(null, args);
|
69
|
+
return fn.apply({
|
70
|
+
__code__: code,
|
71
|
+
__ctx__: context
|
72
|
+
});
|
73
|
+
}
|
74
|
+
Script.prototype.runInContext = function(context) {
|
75
|
+
if (!(context instanceof Context)) {
|
76
|
+
throw new TypeError('needs a \'context\' argument.');
|
77
|
+
}
|
78
|
+
if (global.document) {
|
79
|
+
var iframe = global.document.createElement('iframe');
|
80
|
+
if (!iframe.style) iframe.style = {};
|
81
|
+
iframe.style.display = 'none';
|
82
|
+
|
83
|
+
global.document.body.appendChild(iframe);
|
84
|
+
|
85
|
+
var win = iframe.contentWindow;
|
86
|
+
var wEval = win.eval,
|
87
|
+
wExecScript = win.execScript;
|
88
|
+
|
89
|
+
if (!wEval && wExecScript) {
|
90
|
+
// win.eval() magically appears when this is called in IE:
|
91
|
+
wExecScript.call(win, 'null');
|
92
|
+
wEval = win.eval;
|
93
|
+
}
|
94
|
+
|
95
|
+
forEach(Object_keys(context), function(key) {
|
96
|
+
win[key] = context[key];
|
97
|
+
});
|
98
|
+
forEach(globals, function(key) {
|
99
|
+
if (context[key]) {
|
100
|
+
win[key] = context[key];
|
101
|
+
}
|
102
|
+
});
|
103
|
+
|
104
|
+
var winKeys = Object_keys(win);
|
105
|
+
|
106
|
+
var res = wEval.call(win, this.code);
|
107
|
+
|
108
|
+
forEach(Object_keys(win), function(key) {
|
109
|
+
// Avoid copying circular objects like `top` and `window` by only
|
110
|
+
// updating existing context properties or new properties in the `win`
|
111
|
+
// that was only introduced after the eval.
|
112
|
+
if (key in context || indexOf(winKeys, key) === -1) {
|
113
|
+
context[key] = win[key];
|
114
|
+
}
|
115
|
+
});
|
116
|
+
|
117
|
+
forEach(globals, function(key) {
|
118
|
+
if (!(key in context)) {
|
119
|
+
defineProp(context, key, win[key]);
|
120
|
+
}
|
121
|
+
});
|
122
|
+
global.document.body.removeChild(iframe);
|
123
|
+
|
124
|
+
return res;
|
125
|
+
}
|
126
|
+
return otherRunInContext(this.code, context);
|
127
|
+
};
|
128
|
+
|
129
|
+
Script.prototype.runInThisContext = function() {
|
130
|
+
var fn = new Function('code', 'return eval(code);');
|
131
|
+
return fn.call(global, this.code); // maybe...
|
132
|
+
};
|
133
|
+
|
134
|
+
Script.prototype.runInNewContext = function(context) {
|
135
|
+
var ctx = createContext(context);
|
136
|
+
var res = this.runInContext(ctx);
|
137
|
+
if (context) {
|
138
|
+
forEach(Object_keys(ctx), function(key) {
|
139
|
+
context[key] = ctx[key];
|
140
|
+
});
|
141
|
+
}
|
142
|
+
|
143
|
+
return res;
|
144
|
+
};
|
145
|
+
|
146
|
+
|
147
|
+
export function createScript(code) {
|
148
|
+
return new Script(code);
|
149
|
+
}
|
150
|
+
|
151
|
+
export function createContext(context) {
|
152
|
+
if (isContext(context)) {
|
153
|
+
return context;
|
154
|
+
}
|
155
|
+
var copy = new Context();
|
156
|
+
if (typeof context === 'object') {
|
157
|
+
forEach(Object_keys(context), function(key) {
|
158
|
+
copy[key] = context[key];
|
159
|
+
});
|
160
|
+
}
|
161
|
+
return copy;
|
162
|
+
}
|
163
|
+
export function runInContext(code, contextifiedSandbox, options) {
|
164
|
+
var script = new Script(code, options);
|
165
|
+
return script.runInContext(contextifiedSandbox, options);
|
166
|
+
}
|
167
|
+
export function runInThisContext(code, options) {
|
168
|
+
var script = new Script(code, options);
|
169
|
+
return script.runInThisContext(options);
|
170
|
+
}
|
171
|
+
export function isContext(context) {
|
172
|
+
return context instanceof Context;
|
173
|
+
}
|
174
|
+
export function runInNewContext(code, sandbox, options) {
|
175
|
+
var script = new Script(code, options);
|
176
|
+
return script.runInNewContext(sandbox, options);
|
177
|
+
}
|
178
|
+
export default {
|
179
|
+
runInContext: runInContext,
|
180
|
+
isContext: isContext,
|
181
|
+
createContext: createContext,
|
182
|
+
createScript: createScript,
|
183
|
+
Script: Script,
|
184
|
+
runInThisContext: runInThisContext,
|
185
|
+
runInNewContext: runInNewContext
|
186
|
+
}
|
187
|
+
|
188
|
+
|
189
|
+
/*
|
190
|
+
from indexOf
|
191
|
+
@ author tjholowaychuk
|
192
|
+
@ license MIT
|
193
|
+
*/
|
194
|
+
var _indexOf = [].indexOf;
|
195
|
+
|
196
|
+
function indexOf(arr, obj){
|
197
|
+
if (_indexOf) return arr.indexOf(obj);
|
198
|
+
for (var i = 0; i < arr.length; ++i) {
|
199
|
+
if (arr[i] === obj) return i;
|
200
|
+
}
|
201
|
+
return -1;
|
202
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (C) 2014-2016 by Vitaly Puzrin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
// Note: adler32 takes 12% for level 0 and 2% for level 6.
|
3
|
+
// It doesn't worth to make additional optimizationa as in original.
|
4
|
+
// Small size is preferable.
|
5
|
+
|
6
|
+
function adler32(adler, buf, len, pos) {
|
7
|
+
var s1 = (adler & 0xffff) |0,
|
8
|
+
s2 = ((adler >>> 16) & 0xffff) |0,
|
9
|
+
n = 0;
|
10
|
+
|
11
|
+
while (len !== 0) {
|
12
|
+
// Set limit ~ twice less than 5552, to keep
|
13
|
+
// s2 in 31-bits, because we force signed ints.
|
14
|
+
// in other case %= will fail.
|
15
|
+
n = len > 2000 ? 2000 : len;
|
16
|
+
len -= n;
|
17
|
+
|
18
|
+
do {
|
19
|
+
s1 = (s1 + buf[pos++]) |0;
|
20
|
+
s2 = (s2 + s1) |0;
|
21
|
+
} while (--n);
|
22
|
+
|
23
|
+
s1 %= 65521;
|
24
|
+
s2 %= 65521;
|
25
|
+
}
|
26
|
+
|
27
|
+
return (s1 | (s2 << 16)) |0;
|
28
|
+
}
|
29
|
+
|
30
|
+
|
31
|
+
export default adler32;
|
@@ -0,0 +1,269 @@
|
|
1
|
+
import msg from './messages';
|
2
|
+
import zstream from './zstream';
|
3
|
+
import {deflateInit2, deflateEnd, deflateReset, deflate} from './deflate';
|
4
|
+
import {inflateInit2, inflate, inflateEnd, inflateReset} from './inflate';
|
5
|
+
// import constants from './constants';
|
6
|
+
|
7
|
+
|
8
|
+
// zlib modes
|
9
|
+
export var NONE = 0;
|
10
|
+
export var DEFLATE = 1;
|
11
|
+
export var INFLATE = 2;
|
12
|
+
export var GZIP = 3;
|
13
|
+
export var GUNZIP = 4;
|
14
|
+
export var DEFLATERAW = 5;
|
15
|
+
export var INFLATERAW = 6;
|
16
|
+
export var UNZIP = 7;
|
17
|
+
export var Z_NO_FLUSH= 0,
|
18
|
+
Z_PARTIAL_FLUSH= 1,
|
19
|
+
Z_SYNC_FLUSH= 2,
|
20
|
+
Z_FULL_FLUSH= 3,
|
21
|
+
Z_FINISH= 4,
|
22
|
+
Z_BLOCK= 5,
|
23
|
+
Z_TREES= 6,
|
24
|
+
|
25
|
+
/* Return codes for the compression/decompression functions. Negative values
|
26
|
+
* are errors, positive values are used for special but normal events.
|
27
|
+
*/
|
28
|
+
Z_OK= 0,
|
29
|
+
Z_STREAM_END= 1,
|
30
|
+
Z_NEED_DICT= 2,
|
31
|
+
Z_ERRNO= -1,
|
32
|
+
Z_STREAM_ERROR= -2,
|
33
|
+
Z_DATA_ERROR= -3,
|
34
|
+
//Z_MEM_ERROR: -4,
|
35
|
+
Z_BUF_ERROR= -5,
|
36
|
+
//Z_VERSION_ERROR: -6,
|
37
|
+
|
38
|
+
/* compression levels */
|
39
|
+
Z_NO_COMPRESSION= 0,
|
40
|
+
Z_BEST_SPEED= 1,
|
41
|
+
Z_BEST_COMPRESSION= 9,
|
42
|
+
Z_DEFAULT_COMPRESSION= -1,
|
43
|
+
|
44
|
+
|
45
|
+
Z_FILTERED= 1,
|
46
|
+
Z_HUFFMAN_ONLY= 2,
|
47
|
+
Z_RLE= 3,
|
48
|
+
Z_FIXED= 4,
|
49
|
+
Z_DEFAULT_STRATEGY= 0,
|
50
|
+
|
51
|
+
/* Possible values of the data_type field (though see inflate()) */
|
52
|
+
Z_BINARY= 0,
|
53
|
+
Z_TEXT= 1,
|
54
|
+
//Z_ASCII: 1, // = Z_TEXT (deprecated)
|
55
|
+
Z_UNKNOWN= 2,
|
56
|
+
|
57
|
+
/* The deflate compression method */
|
58
|
+
Z_DEFLATED= 8;
|
59
|
+
export function Zlib(mode) {
|
60
|
+
if (mode < DEFLATE || mode > UNZIP)
|
61
|
+
throw new TypeError('Bad argument');
|
62
|
+
|
63
|
+
this.mode = mode;
|
64
|
+
this.init_done = false;
|
65
|
+
this.write_in_progress = false;
|
66
|
+
this.pending_close = false;
|
67
|
+
this.windowBits = 0;
|
68
|
+
this.level = 0;
|
69
|
+
this.memLevel = 0;
|
70
|
+
this.strategy = 0;
|
71
|
+
this.dictionary = null;
|
72
|
+
}
|
73
|
+
|
74
|
+
Zlib.prototype.init = function(windowBits, level, memLevel, strategy, dictionary) {
|
75
|
+
this.windowBits = windowBits;
|
76
|
+
this.level = level;
|
77
|
+
this.memLevel = memLevel;
|
78
|
+
this.strategy = strategy;
|
79
|
+
// dictionary not supported.
|
80
|
+
|
81
|
+
if (this.mode === GZIP || this.mode === GUNZIP)
|
82
|
+
this.windowBits += 16;
|
83
|
+
|
84
|
+
if (this.mode === UNZIP)
|
85
|
+
this.windowBits += 32;
|
86
|
+
|
87
|
+
if (this.mode === DEFLATERAW || this.mode === INFLATERAW)
|
88
|
+
this.windowBits = -this.windowBits;
|
89
|
+
|
90
|
+
this.strm = new zstream();
|
91
|
+
var status;
|
92
|
+
switch (this.mode) {
|
93
|
+
case DEFLATE:
|
94
|
+
case GZIP:
|
95
|
+
case DEFLATERAW:
|
96
|
+
status = deflateInit2(
|
97
|
+
this.strm,
|
98
|
+
this.level,
|
99
|
+
Z_DEFLATED,
|
100
|
+
this.windowBits,
|
101
|
+
this.memLevel,
|
102
|
+
this.strategy
|
103
|
+
);
|
104
|
+
break;
|
105
|
+
case INFLATE:
|
106
|
+
case GUNZIP:
|
107
|
+
case INFLATERAW:
|
108
|
+
case UNZIP:
|
109
|
+
status = inflateInit2(
|
110
|
+
this.strm,
|
111
|
+
this.windowBits
|
112
|
+
);
|
113
|
+
break;
|
114
|
+
default:
|
115
|
+
throw new Error('Unknown mode ' + this.mode);
|
116
|
+
}
|
117
|
+
|
118
|
+
if (status !== Z_OK) {
|
119
|
+
this._error(status);
|
120
|
+
return;
|
121
|
+
}
|
122
|
+
|
123
|
+
this.write_in_progress = false;
|
124
|
+
this.init_done = true;
|
125
|
+
};
|
126
|
+
|
127
|
+
Zlib.prototype.params = function() {
|
128
|
+
throw new Error('deflateParams Not supported');
|
129
|
+
};
|
130
|
+
|
131
|
+
Zlib.prototype._writeCheck = function() {
|
132
|
+
if (!this.init_done)
|
133
|
+
throw new Error('write before init');
|
134
|
+
|
135
|
+
if (this.mode === NONE)
|
136
|
+
throw new Error('already finalized');
|
137
|
+
|
138
|
+
if (this.write_in_progress)
|
139
|
+
throw new Error('write already in progress');
|
140
|
+
|
141
|
+
if (this.pending_close)
|
142
|
+
throw new Error('close is pending');
|
143
|
+
};
|
144
|
+
|
145
|
+
Zlib.prototype.write = function(flush, input, in_off, in_len, out, out_off, out_len) {
|
146
|
+
this._writeCheck();
|
147
|
+
this.write_in_progress = true;
|
148
|
+
|
149
|
+
var self = this;
|
150
|
+
process.nextTick(function() {
|
151
|
+
self.write_in_progress = false;
|
152
|
+
var res = self._write(flush, input, in_off, in_len, out, out_off, out_len);
|
153
|
+
self.callback(res[0], res[1]);
|
154
|
+
|
155
|
+
if (self.pending_close)
|
156
|
+
self.close();
|
157
|
+
});
|
158
|
+
|
159
|
+
return this;
|
160
|
+
};
|
161
|
+
|
162
|
+
// set method for Node buffers, used by pako
|
163
|
+
function bufferSet(data, offset) {
|
164
|
+
for (var i = 0; i < data.length; i++) {
|
165
|
+
this[offset + i] = data[i];
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
Zlib.prototype.writeSync = function(flush, input, in_off, in_len, out, out_off, out_len) {
|
170
|
+
this._writeCheck();
|
171
|
+
return this._write(flush, input, in_off, in_len, out, out_off, out_len);
|
172
|
+
};
|
173
|
+
|
174
|
+
Zlib.prototype._write = function(flush, input, in_off, in_len, out, out_off, out_len) {
|
175
|
+
this.write_in_progress = true;
|
176
|
+
|
177
|
+
if (flush !== Z_NO_FLUSH &&
|
178
|
+
flush !== Z_PARTIAL_FLUSH &&
|
179
|
+
flush !== Z_SYNC_FLUSH &&
|
180
|
+
flush !== Z_FULL_FLUSH &&
|
181
|
+
flush !== Z_FINISH &&
|
182
|
+
flush !== Z_BLOCK) {
|
183
|
+
throw new Error('Invalid flush value');
|
184
|
+
}
|
185
|
+
|
186
|
+
if (input == null) {
|
187
|
+
input = new Buffer(0);
|
188
|
+
in_len = 0;
|
189
|
+
in_off = 0;
|
190
|
+
}
|
191
|
+
|
192
|
+
if (out._set)
|
193
|
+
out.set = out._set;
|
194
|
+
else
|
195
|
+
out.set = bufferSet;
|
196
|
+
|
197
|
+
var strm = this.strm;
|
198
|
+
strm.avail_in = in_len;
|
199
|
+
strm.input = input;
|
200
|
+
strm.next_in = in_off;
|
201
|
+
strm.avail_out = out_len;
|
202
|
+
strm.output = out;
|
203
|
+
strm.next_out = out_off;
|
204
|
+
var status;
|
205
|
+
switch (this.mode) {
|
206
|
+
case DEFLATE:
|
207
|
+
case GZIP:
|
208
|
+
case DEFLATERAW:
|
209
|
+
status = deflate(strm, flush);
|
210
|
+
break;
|
211
|
+
case UNZIP:
|
212
|
+
case INFLATE:
|
213
|
+
case GUNZIP:
|
214
|
+
case INFLATERAW:
|
215
|
+
status = inflate(strm, flush);
|
216
|
+
break;
|
217
|
+
default:
|
218
|
+
throw new Error('Unknown mode ' + this.mode);
|
219
|
+
}
|
220
|
+
|
221
|
+
if (status !== Z_STREAM_END && status !== Z_OK) {
|
222
|
+
this._error(status);
|
223
|
+
}
|
224
|
+
|
225
|
+
this.write_in_progress = false;
|
226
|
+
return [strm.avail_in, strm.avail_out];
|
227
|
+
};
|
228
|
+
|
229
|
+
Zlib.prototype.close = function() {
|
230
|
+
if (this.write_in_progress) {
|
231
|
+
this.pending_close = true;
|
232
|
+
return;
|
233
|
+
}
|
234
|
+
|
235
|
+
this.pending_close = false;
|
236
|
+
|
237
|
+
if (this.mode === DEFLATE || this.mode === GZIP || this.mode === DEFLATERAW) {
|
238
|
+
deflateEnd(this.strm);
|
239
|
+
} else {
|
240
|
+
inflateEnd(this.strm);
|
241
|
+
}
|
242
|
+
|
243
|
+
this.mode = NONE;
|
244
|
+
};
|
245
|
+
var status
|
246
|
+
Zlib.prototype.reset = function() {
|
247
|
+
switch (this.mode) {
|
248
|
+
case DEFLATE:
|
249
|
+
case DEFLATERAW:
|
250
|
+
status = deflateReset(this.strm);
|
251
|
+
break;
|
252
|
+
case INFLATE:
|
253
|
+
case INFLATERAW:
|
254
|
+
status = inflateReset(this.strm);
|
255
|
+
break;
|
256
|
+
}
|
257
|
+
|
258
|
+
if (status !== Z_OK) {
|
259
|
+
this._error(status);
|
260
|
+
}
|
261
|
+
};
|
262
|
+
|
263
|
+
Zlib.prototype._error = function(status) {
|
264
|
+
this.onerror(msg[status] + ': ' + this.strm.msg, status);
|
265
|
+
|
266
|
+
this.write_in_progress = false;
|
267
|
+
if (this.pending_close)
|
268
|
+
this.close();
|
269
|
+
};
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
// Note: we can't get significant speed boost here.
|
3
|
+
// So write code to minimize size - no pregenerated tables
|
4
|
+
// and array tools dependencies.
|
5
|
+
|
6
|
+
|
7
|
+
// Use ordinary array, since untyped makes no boost here
|
8
|
+
function makeTable() {
|
9
|
+
var c, table = [];
|
10
|
+
|
11
|
+
for (var n = 0; n < 256; n++) {
|
12
|
+
c = n;
|
13
|
+
for (var k = 0; k < 8; k++) {
|
14
|
+
c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
|
15
|
+
}
|
16
|
+
table[n] = c;
|
17
|
+
}
|
18
|
+
|
19
|
+
return table;
|
20
|
+
}
|
21
|
+
|
22
|
+
// Create table on load. Just 255 signed longs. Not a problem.
|
23
|
+
var crcTable = makeTable();
|
24
|
+
|
25
|
+
|
26
|
+
function crc32(crc, buf, len, pos) {
|
27
|
+
var t = crcTable,
|
28
|
+
end = pos + len;
|
29
|
+
|
30
|
+
crc ^= -1;
|
31
|
+
|
32
|
+
for (var i = pos; i < end; i++) {
|
33
|
+
crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
|
34
|
+
}
|
35
|
+
|
36
|
+
return (crc ^ (-1)); // >>> 0;
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
export default crc32;
|