zlib.js 4.3 KB

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