|
300 | 300 | // constants object. Node.js zlib.constants bundles all Z_ values plus |
301 | 301 | // DEFLATE (1), INFLATE (2), GZIP (3), DEFLATERAW (4), INFLATERAW (5), |
302 | 302 | // UNZIP (6), GUNZIP (7). Packages like ssh2 destructure constants. |
| 303 | + var zlibConstants = typeof result.constants === 'object' && result.constants !== null |
| 304 | + ? result.constants |
| 305 | + : {}; |
303 | 306 | if (typeof result.constants !== 'object' || result.constants === null) { |
304 | | - var zlibConstants = {}; |
305 | 307 | var constKeys = Object.keys(result); |
306 | 308 | for (var ci = 0; ci < constKeys.length; ci++) { |
307 | 309 | var ck = constKeys[ci]; |
308 | 310 | if (ck.indexOf('Z_') === 0 && typeof result[ck] === 'number') { |
309 | 311 | zlibConstants[ck] = result[ck]; |
310 | 312 | } |
311 | 313 | } |
| 314 | + // Add Z_* constants that esbuild may strip from the browserify-zlib bundle. |
| 315 | + if (typeof zlibConstants.Z_NO_FLUSH !== 'number') zlibConstants.Z_NO_FLUSH = 0; |
| 316 | + if (typeof zlibConstants.Z_PARTIAL_FLUSH !== 'number') zlibConstants.Z_PARTIAL_FLUSH = 1; |
| 317 | + if (typeof zlibConstants.Z_SYNC_FLUSH !== 'number') zlibConstants.Z_SYNC_FLUSH = 2; |
| 318 | + if (typeof zlibConstants.Z_FULL_FLUSH !== 'number') zlibConstants.Z_FULL_FLUSH = 3; |
| 319 | + if (typeof zlibConstants.Z_FINISH !== 'number') zlibConstants.Z_FINISH = 4; |
| 320 | + if (typeof zlibConstants.Z_BLOCK !== 'number') zlibConstants.Z_BLOCK = 5; |
| 321 | + if (typeof zlibConstants.Z_TREES !== 'number') zlibConstants.Z_TREES = 6; |
| 322 | + if (typeof zlibConstants.Z_OK !== 'number') zlibConstants.Z_OK = 0; |
| 323 | + if (typeof zlibConstants.Z_STREAM_END !== 'number') zlibConstants.Z_STREAM_END = 1; |
| 324 | + if (typeof zlibConstants.Z_NEED_DICT !== 'number') zlibConstants.Z_NEED_DICT = 2; |
| 325 | + if (typeof zlibConstants.Z_ERRNO !== 'number') zlibConstants.Z_ERRNO = -1; |
| 326 | + if (typeof zlibConstants.Z_STREAM_ERROR !== 'number') zlibConstants.Z_STREAM_ERROR = -2; |
| 327 | + if (typeof zlibConstants.Z_DATA_ERROR !== 'number') zlibConstants.Z_DATA_ERROR = -3; |
| 328 | + if (typeof zlibConstants.Z_MEM_ERROR !== 'number') zlibConstants.Z_MEM_ERROR = -4; |
| 329 | + if (typeof zlibConstants.Z_BUF_ERROR !== 'number') zlibConstants.Z_BUF_ERROR = -5; |
| 330 | + if (typeof zlibConstants.Z_VERSION_ERROR !== 'number') zlibConstants.Z_VERSION_ERROR = -6; |
| 331 | + if (typeof zlibConstants.Z_NO_COMPRESSION !== 'number') zlibConstants.Z_NO_COMPRESSION = 0; |
| 332 | + if (typeof zlibConstants.Z_BEST_SPEED !== 'number') zlibConstants.Z_BEST_SPEED = 1; |
| 333 | + if (typeof zlibConstants.Z_BEST_COMPRESSION !== 'number') zlibConstants.Z_BEST_COMPRESSION = 9; |
| 334 | + if (typeof zlibConstants.Z_DEFAULT_COMPRESSION !== 'number') zlibConstants.Z_DEFAULT_COMPRESSION = -1; |
| 335 | + if (typeof zlibConstants.Z_FILTERED !== 'number') zlibConstants.Z_FILTERED = 1; |
| 336 | + if (typeof zlibConstants.Z_HUFFMAN_ONLY !== 'number') zlibConstants.Z_HUFFMAN_ONLY = 2; |
| 337 | + if (typeof zlibConstants.Z_RLE !== 'number') zlibConstants.Z_RLE = 3; |
| 338 | + if (typeof zlibConstants.Z_FIXED !== 'number') zlibConstants.Z_FIXED = 4; |
| 339 | + if (typeof zlibConstants.Z_DEFAULT_STRATEGY !== 'number') zlibConstants.Z_DEFAULT_STRATEGY = 0; |
312 | 340 | // Add mode constants that Node.js exposes but browserify-zlib does not. |
313 | 341 | if (typeof zlibConstants.DEFLATE !== 'number') zlibConstants.DEFLATE = 1; |
314 | 342 | if (typeof zlibConstants.INFLATE !== 'number') zlibConstants.INFLATE = 2; |
|
317 | 345 | if (typeof zlibConstants.INFLATERAW !== 'number') zlibConstants.INFLATERAW = 5; |
318 | 346 | if (typeof zlibConstants.UNZIP !== 'number') zlibConstants.UNZIP = 6; |
319 | 347 | if (typeof zlibConstants.GUNZIP !== 'number') zlibConstants.GUNZIP = 7; |
320 | | - result.constants = zlibConstants; |
321 | 348 | } |
| 349 | + result.constants = zlibConstants; |
322 | 350 | return result; |
323 | 351 | } |
324 | 352 |
|
|
0 commit comments