| 1 | /* zlib.js -- JavaScript implementation for the zlib. |
| 2 | Version: 0.2.0 |
| 3 | LastModified: Apr 12 2012 |
| 4 | Copyright (C) 2012 Masanao Izumo <iz@onicos.co.jp> |
| 5 | |
| 6 | The original copyright notice (zlib 1.2.6): |
| 7 | |
| 8 | Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler |
| 9 | |
| 10 | This software is provided 'as-is', without any express or implied |
| 11 | warranty. In no event will the authors be held liable for any damages |
| 12 | arising from the use of this software. |
| 13 | |
| 14 | Permission is granted to anyone to use this software for any purpose, |
| 15 | including commercial applications, and to alter it and redistribute it |
| 16 | freely, subject to the following restrictions: |
| 17 | |
| 18 | 1. The origin of this software must not be misrepresented; you must not |
| 19 | claim that you wrote the original software. If you use this software |
| 20 | in a product, an acknowledgment in the product documentation would be |
| 21 | appreciated but is not required. |
| 22 | 2. Altered source versions must be plainly marked as such, and must not be |
| 23 | misrepresented as being the original software. |
| 24 | 3. This notice may not be removed or altered from any source distribution. |
| 25 | |
| 26 | Jean-loup Gailly Mark Adler |
| 27 | jloup@gzip.org madler@alumni.caltech.edu |
| 28 | |
| 29 | |
| 30 | The data format used by the zlib library is described by RFCs (Request for |
| 31 | Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 |
| 32 | (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). |
| 33 | */ |
| 34 | |
| 35 | var ZLIB = ( ZLIB || {} ); // ZLIB namespace initialization |
| 36 | |
| 37 | // common definitions |
| 38 | if(typeof ZLIB.common_initialized === 'undefined') { |
| 39 | ZLIB.Z_NO_FLUSH = 0; |
| 40 | ZLIB.Z_PARTIAL_FLUSH = 1; |
| 41 | ZLIB.Z_SYNC_FLUSH = 2; |
| 42 | ZLIB.Z_FULL_FLUSH = 3; |
| 43 | ZLIB.Z_FINISH = 4; |
| 44 | ZLIB.Z_BLOCK = 5; |
| 45 | ZLIB.Z_TREES = 6; |
| 46 | /* Allowed flush values; see deflate() and inflate() below for details */ |
| 47 | |
| 48 | ZLIB.Z_OK = 0; |
| 49 | ZLIB.Z_STREAM_END = 1; |
| 50 | ZLIB.Z_NEED_DICT = 2; |
| 51 | ZLIB.Z_ERRNO = (-1); |
| 52 | ZLIB.Z_STREAM_ERROR = (-2); |
| 53 | ZLIB.Z_DATA_ERROR = (-3); |
| 54 | ZLIB.Z_MEM_ERROR = (-4); |
| 55 | ZLIB.Z_BUF_ERROR = (-5); |
| 56 | ZLIB.Z_VERSION_ERROR = (-6); |
| 57 | /* Return codes for the compression/decompression functions. Negative values |
| 58 | * are errors, positive values are used for special but normal events. |
| 59 | */ |
| 60 | |
| 61 | ZLIB.Z_DEFLATED = 8; /* The deflate compression method (the only one supported in this version) */ |
| 62 | |
| 63 | /** |
| 64 | * z_stream constructor |
| 65 | * @constructor |
| 66 | */ |
| 67 | ZLIB.z_stream = function() { |
| 68 | this.next_in = 0; /* next input byte */ |
| 69 | this.avail_in = 0; /* number of bytes available in input_data */ |
| 70 | this.total_in = 0; /* total number of input bytes read so far */ |
| 71 | |
| 72 | this.next_out = 0; /* next output byte */ |
| 73 | this.avail_out = 0; /* remaining free space at next_out */ |
| 74 | this.total_out = 0; /* total number of bytes output so far */ |
| 75 | |
| 76 | this.msg = null; /* last error message, null if no error */ |
| 77 | this.state = null; /* not visible by applications */ |
| 78 | |
| 79 | this.data_type = 0; /* best guess about the data type: binary or text */ |
| 80 | this.adler = 0; /* TODO: adler32 value of the uncompressed data */ |
| 81 | |
| 82 | // zlib.js |
| 83 | this.input_data = ''; /* input data */ |
| 84 | this.output_data = ''; /* output data */ |
| 85 | this.error = 0; /* error code */ |
| 86 | this.checksum_function = null; /* crc32(for gzip) or adler32(for zlib) */ |
| 87 | }; |
| 88 | |
| 89 | /** |
| 90 | * TODO |
| 91 | * @constructor |
| 92 | */ |
| 93 | ZLIB.gz_header = function() { |
| 94 | this.text = 0; /* true if compressed data believed to be text */ |
| 95 | this.time = 0; /* modification time */ |
| 96 | this.xflags = 0; /* extra flags (not used when writing a gzip file) */ |
| 97 | this.os = 0xff; /* operating system */ |
| 98 | this.extra = null; /* extra field string or null if none */ |
| 99 | this.extra_len = 0; /* this.extra.length (only when reading header) */ |
| 100 | this.extra_max = 0; /* space at extra (only when reading header) */ |
| 101 | this.name = null; /* file name string or null if none */ |
| 102 | this.name_max = 0; /* space at name (only when reading header) */ |
| 103 | this.comment = null; /* comment string or null if none */ |
| 104 | this.comm_max = 0; /* space at comment (only when reading header) */ |
| 105 | this.hcrc = 0; /* true if there was or will be a header crc */ |
| 106 | this.done = 0; /* true when done reading gzip header (not used |
| 107 | when writing a gzip file) */ |
| 108 | }; |
| 109 | |
| 110 | ZLIB.common_initialized = true; |
| 111 | } // common definitions |