{
    "content": [
        {
            "type": "text",
            "text": "# Compress::Raw::Zlib (perldoc)\n\n**Summary:** Compress::Raw::Zlib - Low-Level Interface to zlib compression library\n\n**Synopsis:** use Compress::Raw::Zlib ;\n($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] ) ;\n$status = $d->deflate($input, $output) ;\n$status = $d->flush($output [, $flushtype]) ;\n$d->deflateReset() ;\n$d->deflateParams(OPTS) ;\n$d->deflateTune(OPTS) ;\n$d->dictadler() ;\n$d->crc32() ;\n$d->adler32() ;\n$d->totalin() ;\n$d->totalout() ;\n$d->msg() ;\n$d->getStrategy();\n$d->getLevel();\n$d->getBufSize();\n($i, $status) = new Compress::Raw::Zlib::Inflate( [OPT] ) ;\n$status = $i->inflate($input, $output [, $eof]) ;\n$status = $i->inflateSync($input) ;\n$i->inflateReset() ;\n$i->dictadler() ;\n$d->crc32() ;\n$d->adler32() ;\n$i->totalin() ;\n$i->totalout() ;\n$i->msg() ;\n$d->getBufSize();\n$crc = adler32($buffer [,$crc]) ;\n$crc = crc32($buffer [,$crc]) ;\n$crc = crc32combine($crc1, $crc2, $len2);\n$adler = adler32combine($adler1, $adler2, $len2);\nmy $version = Compress::Raw::Zlib::zlibversion();\nmy $flags = Compress::Raw::Zlib::zlibCompileFlags();\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (39 lines)\n- **DESCRIPTION** (3 lines)\n- **Compress::Raw::Zlib::Deflate** (26 lines) — 14 subsections\n  - -Level (5 lines)\n  - -Method (3 lines)\n  - -WindowBits (12 lines)\n  - -MemLevel (5 lines)\n  - -Strategy (5 lines)\n  - -Dictionary (6 lines)\n  - -Bufsize (6 lines)\n  - -AppendOutput (11 lines)\n  - -CRC32 (5 lines)\n  - -ADLER32 (63 lines)\n  - -Level (3 lines)\n  - -Strategy (3 lines)\n  - -BufSize (41 lines)\n  - Example (31 lines)\n- **Compress::Raw::Zlib::Inflate** (24 lines) — 9 subsections\n  - -WindowBits (15 lines)\n  - -Bufsize (6 lines)\n  - -Dictionary (2 lines)\n  - -AppendOutput (10 lines)\n  - -CRC32 (5 lines)\n  - -ADLER32 (5 lines)\n  - -ConsumeInput (9 lines)\n  - -LimitOutput (118 lines)\n  - Examples (65 lines)\n- **CHECKSUM FUNCTIONS** (20 lines)\n- **Misc** (121 lines)\n- **ACCESSING ZIP FILES** (4 lines)\n- **FAQ** (25 lines) — 2 subsections\n  - Accessing .tar.Z files (38 lines)\n  - Zlib Library Version Support (11 lines)\n- **CONSTANTS** (2 lines)\n- **SUPPORT** (4 lines)\n- **SEE ALSO** (22 lines)\n- **AUTHOR** (2 lines)\n- **MODIFICATION HISTORY** (2 lines)\n- **COPYRIGHT AND LICENSE** (5 lines)\n\n## Full Content\n\n### NAME\n\nCompress::Raw::Zlib - Low-Level Interface to zlib compression library\n\n### SYNOPSIS\n\nuse Compress::Raw::Zlib ;\n\n($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] ) ;\n$status = $d->deflate($input, $output) ;\n$status = $d->flush($output [, $flushtype]) ;\n$d->deflateReset() ;\n$d->deflateParams(OPTS) ;\n$d->deflateTune(OPTS) ;\n$d->dictadler() ;\n$d->crc32() ;\n$d->adler32() ;\n$d->totalin() ;\n$d->totalout() ;\n$d->msg() ;\n$d->getStrategy();\n$d->getLevel();\n$d->getBufSize();\n\n($i, $status) = new Compress::Raw::Zlib::Inflate( [OPT] ) ;\n$status = $i->inflate($input, $output [, $eof]) ;\n$status = $i->inflateSync($input) ;\n$i->inflateReset() ;\n$i->dictadler() ;\n$d->crc32() ;\n$d->adler32() ;\n$i->totalin() ;\n$i->totalout() ;\n$i->msg() ;\n$d->getBufSize();\n\n$crc = adler32($buffer [,$crc]) ;\n$crc = crc32($buffer [,$crc]) ;\n\n$crc = crc32combine($crc1, $crc2, $len2);\n$adler = adler32combine($adler1, $adler2, $len2);\n\nmy $version = Compress::Raw::Zlib::zlibversion();\nmy $flags = Compress::Raw::Zlib::zlibCompileFlags();\n\n### DESCRIPTION\n\nThe *Compress::Raw::Zlib* module provides a Perl interface to the *zlib* compression library\n(see \"AUTHOR\" for details about where to get *zlib*).\n\n### Compress::Raw::Zlib::Deflate\n\nThis section defines an interface that allows in-memory compression using the *deflate*\ninterface provided by zlib.\n\nHere is a definition of the interface available:\n\n($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] )\nInitialises a deflation object.\n\nIf you are familiar with the *zlib* library, it combines the features of the *zlib* functions\n\"deflateInit\", \"deflateInit2\" and \"deflateSetDictionary\".\n\nIf successful, it will return the initialised deflation object, $d and a $status of \"ZOK\" in a\nlist context. In scalar context it returns the deflation object, $d, only.\n\nIf not successful, the returned deflation object, $d, will be *undef* and $status will hold the\na *zlib* error code.\n\nThe function optionally takes a number of named options specified as \"Name => value\" pairs. This\nallows individual options to be tailored without having to specify them all in the parameter\nlist.\n\nFor backward compatibility, it is also possible to pass the parameters as a reference to a hash\ncontaining the name=>value pairs.\n\nBelow is a list of the valid options:\n\n#### -Level\n\nDefines the compression level. Valid values are 0 through 9, \"ZNOCOMPRESSION\",\n\"ZBESTSPEED\", \"ZBESTCOMPRESSION\", and \"ZDEFAULTCOMPRESSION\".\n\nThe default is \"ZDEFAULTCOMPRESSION\".\n\n#### -Method\n\nDefines the compression method. The only valid value at present (and the default) is\n\"ZDEFLATED\".\n\n#### -WindowBits\n\nTo compress an RFC 1950 data stream, set \"WindowBits\" to a positive number between 8 and\n15.\n\nTo compress an RFC 1951 data stream, set \"WindowBits\" to \"-MAXWBITS\".\n\nTo compress an RFC 1952 data stream (i.e. gzip), set \"WindowBits\" to \"WANTGZIP\".\n\nFor a definition of the meaning and valid values for \"WindowBits\" refer to the *zlib*\ndocumentation for *deflateInit2*.\n\nDefaults to \"MAXWBITS\".\n\n#### -MemLevel\n\nFor a definition of the meaning and valid values for \"MemLevel\" refer to the *zlib*\ndocumentation for *deflateInit2*.\n\nDefaults to MAXMEMLEVEL.\n\n#### -Strategy\n\nDefines the strategy used to tune the compression. The valid values are\n\"ZDEFAULTSTRATEGY\", \"ZFILTERED\", \"ZRLE\", \"ZFIXED\" and \"ZHUFFMANONLY\".\n\nThe default is \"ZDEFAULTSTRATEGY\".\n\n#### -Dictionary\n\nWhen a dictionary is specified *Compress::Raw::Zlib* will automatically call\n\"deflateSetDictionary\" directly after calling \"deflateInit\". The Adler32 value for the\ndictionary can be obtained by calling the method \"$d->dictadler()\".\n\nThe default is no dictionary.\n\n#### -Bufsize\n\nSets the initial size for the output buffer used by the \"$d->deflate\" and \"$d->flush\"\nmethods. If the buffer has to be reallocated to increase the size, it will grow in\nincrements of \"Bufsize\".\n\nThe default buffer size is 4096.\n\n#### -AppendOutput\n\nThis option controls how data is written to the output buffer by the \"$d->deflate\" and\n\"$d->flush\" methods.\n\nIf the \"AppendOutput\" option is set to false, the output buffers in the \"$d->deflate\" and\n\"$d->flush\" methods will be truncated before uncompressed data is written to them.\n\nIf the option is set to true, uncompressed data will be appended to the output buffer in\nthe \"$d->deflate\" and \"$d->flush\" methods.\n\nThis option defaults to false.\n\n#### -CRC32\n\nIf set to true, a crc32 checksum of the uncompressed data will be calculated. Use the\n\"$d->crc32\" method to retrieve this value.\n\nThis option defaults to false.\n\n#### -ADLER32\n\nIf set to true, an adler32 checksum of the uncompressed data will be calculated. Use the\n\"$d->adler32\" method to retrieve this value.\n\nThis option defaults to false.\n\nHere is an example of using the \"Compress::Raw::Zlib::Deflate\" optional parameter list to\noverride the default buffer size and compression level. All other options will take their\ndefault values.\n\nmy $d = new Compress::Raw::Zlib::Deflate ( -Bufsize => 300,\n-Level   => ZBESTSPEED ) ;\n\n$status = $d->deflate($input, $output)\nDeflates the contents of $input and writes the compressed data to $output.\n\nThe $input and $output parameters can be either scalars or scalar references.\n\nWhen finished, $input will be completely processed (assuming there were no errors). If the\ndeflation was successful it writes the deflated data to $output and returns a status value of\n\"ZOK\".\n\nOn error, it returns a *zlib* error code.\n\nIf the \"AppendOutput\" option is set to true in the constructor for the $d object, the compressed\ndata will be appended to $output. If it is false, $output will be truncated before any\ncompressed data is written to it.\n\nNote: This method will not necessarily write compressed data to $output every time it is called.\nSo do not assume that there has been an error if the contents of $output is empty on returning\nfrom this method. As long as the return code from the method is \"ZOK\", the deflate has\nsucceeded.\n\n$status = $d->flush($output [, $flushtype])\nTypically used to finish the deflation. Any pending output will be written to $output.\n\nReturns \"ZOK\" if successful.\n\nNote that flushing can seriously degrade the compression ratio, so it should only be used to\nterminate a decompression (using \"ZFINISH\") or when you want to create a *full flush point*\n(using \"ZFULLFLUSH\").\n\nBy default the \"flushtype\" used is \"ZFINISH\". Other valid values for \"flushtype\" are\n\"ZNOFLUSH\", \"ZPARTIALFLUSH\", \"ZSYNCFLUSH\" and \"ZFULLFLUSH\". It is strongly recommended\nthat you only set the \"flushtype\" parameter if you fully understand the implications of what it\ndoes. See the \"zlib\" documentation for details.\n\nIf the \"AppendOutput\" option is set to true in the constructor for the $d object, the compressed\ndata will be appended to $output. If it is false, $output will be truncated before any\ncompressed data is written to it.\n\n$status = $d->deflateReset()\nThis method will reset the deflation object $d. It can be used when you are compressing multiple\ndata streams and want to use the same object to compress each of them. It should only be used\nonce the previous data stream has been flushed successfully, i.e. a call to\n\"$d->flush(ZFINISH)\" has returned \"ZOK\".\n\nReturns \"ZOK\" if successful.\n\n$status = $d->deflateParams([OPT])\nChange settings for the deflate object $d.\n\nThe list of the valid options is shown below. Options not specified will remain unchanged.\n\n#### -Level\n\nDefines the compression level. Valid values are 0 through 9, \"ZNOCOMPRESSION\",\n\"ZBESTSPEED\", \"ZBESTCOMPRESSION\", and \"ZDEFAULTCOMPRESSION\".\n\n#### -Strategy\n\nDefines the strategy used to tune the compression. The valid values are\n\"ZDEFAULTSTRATEGY\", \"ZFILTERED\" and \"ZHUFFMANONLY\".\n\n#### -BufSize\n\nSets the initial size for the output buffer used by the \"$d->deflate\" and \"$d->flush\"\nmethods. If the buffer has to be reallocated to increase the size, it will grow in\nincrements of \"Bufsize\".\n\n$status = $d->deflateTune($goodlength, $maxlazy, $nicelength, $maxchain)\nTune the internal settings for the deflate object $d. This option is only available if you are\nrunning zlib 1.2.2.3 or better.\n\nRefer to the documentation in zlib.h for instructions on how to fly \"deflateTune\".\n\n$d->dictadler()\nReturns the adler32 value for the dictionary.\n\n$d->crc32()\nReturns the crc32 value for the uncompressed data to date.\n\nIf the \"CRC32\" option is not enabled in the constructor for this object, this method will always\nreturn 0;\n\n$d->adler32()\nReturns the adler32 value for the uncompressed data to date.\n\n$d->msg()\nReturns the last error message generated by zlib.\n\n$d->totalin()\nReturns the total number of bytes uncompressed bytes input to deflate.\n\n$d->totalout()\nReturns the total number of compressed bytes output from deflate.\n\n$d->getStrategy()\nReturns the deflation strategy currently used. Valid values are \"ZDEFAULTSTRATEGY\",\n\"ZFILTERED\" and \"ZHUFFMANONLY\".\n\n$d->getLevel()\nReturns the compression level being used.\n\n$d->getBufSize()\nReturns the buffer size used to carry out the compression.\n\n#### Example\n\nHere is a trivial example of using \"deflate\". It simply reads standard input, deflates it and\nwrites it to standard output.\n\nuse strict ;\nuse warnings ;\n\nuse Compress::Raw::Zlib ;\n\nbinmode STDIN;\nbinmode STDOUT;\nmy $x = new Compress::Raw::Zlib::Deflate\nor die \"Cannot create a deflation stream\\n\" ;\n\nmy ($output, $status) ;\nwhile (<>)\n{\n$status = $x->deflate($, $output) ;\n\n$status == ZOK\nor die \"deflation failed\\n\" ;\n\nprint $output ;\n}\n\n$status = $x->flush($output) ;\n\n$status == ZOK\nor die \"deflation failed\\n\" ;\n\nprint $output ;\n\n### Compress::Raw::Zlib::Inflate\n\nThis section defines an interface that allows in-memory uncompression using the *inflate*\ninterface provided by zlib.\n\nHere is a definition of the interface:\n\n($i, $status) = new Compress::Raw::Zlib::Inflate( [OPT] )\nInitialises an inflation object.\n\nIn a list context it returns the inflation object, $i, and the *zlib* status code ($status). In\na scalar context it returns the inflation object only.\n\nIf successful, $i will hold the inflation object and $status will be \"ZOK\".\n\nIf not successful, $i will be *undef* and $status will hold the *zlib* error code.\n\nThe function optionally takes a number of named options specified as \"-Name => value\" pairs.\nThis allows individual options to be tailored without having to specify them all in the\nparameter list.\n\nFor backward compatibility, it is also possible to pass the parameters as a reference to a hash\ncontaining the \"name=>value\" pairs.\n\nHere is a list of the valid options:\n\n#### -WindowBits\n\nTo uncompress an RFC 1950 data stream, set \"WindowBits\" to a positive number between 8 and\n15.\n\nTo uncompress an RFC 1951 data stream, set \"WindowBits\" to \"-MAXWBITS\".\n\nTo uncompress an RFC 1952 data stream (i.e. gzip), set \"WindowBits\" to \"WANTGZIP\".\n\nTo auto-detect and uncompress an RFC 1950 or RFC 1952 data stream (i.e. gzip), set\n\"WindowBits\" to \"WANTGZIPORZLIB\".\n\nFor a full definition of the meaning and valid values for \"WindowBits\" refer to the *zlib*\ndocumentation for *inflateInit2*.\n\nDefaults to \"MAXWBITS\".\n\n#### -Bufsize\n\nSets the initial size for the output buffer used by the \"$i->inflate\" method. If the output\nbuffer in this method has to be reallocated to increase the size, it will grow in\nincrements of \"Bufsize\".\n\nDefault is 4096.\n\n#### -Dictionary\n\nThe default is no dictionary.\n\n#### -AppendOutput\n\nThis option controls how data is written to the output buffer by the \"$i->inflate\" method.\n\nIf the option is set to false, the output buffer in the \"$i->inflate\" method will be\ntruncated before uncompressed data is written to it.\n\nIf the option is set to true, uncompressed data will be appended to the output buffer by\nthe \"$i->inflate\" method.\n\nThis option defaults to false.\n\n#### -CRC32\n\nIf set to true, a crc32 checksum of the uncompressed data will be calculated. Use the\n\"$i->crc32\" method to retrieve this value.\n\nThis option defaults to false.\n\n#### -ADLER32\n\nIf set to true, an adler32 checksum of the uncompressed data will be calculated. Use the\n\"$i->adler32\" method to retrieve this value.\n\nThis option defaults to false.\n\n#### -ConsumeInput\n\nIf set to true, this option will remove compressed data from the input buffer of the\n\"$i->inflate\" method as the inflate progresses.\n\nThis option can be useful when you are processing compressed data that is embedded in\nanother file/buffer. In this case the data that immediately follows the compressed stream\nwill be left in the input buffer.\n\nThis option defaults to true.\n\n#### -LimitOutput\n\nThe \"LimitOutput\" option changes the behavior of the \"$i->inflate\" method so that the\namount of memory used by the output buffer can be limited.\n\nWhen \"LimitOutput\" is used the size of the output buffer used will either be the value of\nthe \"Bufsize\" option or the amount of memory already allocated to $output, whichever is\nlarger. Predicting the output size available is tricky, so don't rely on getting an exact\noutput buffer size.\n\nWhen \"LimitOutout\" is not specified \"$i->inflate\" will use as much memory as it takes to\nwrite all the uncompressed data it creates by uncompressing the input buffer.\n\nIf \"LimitOutput\" is enabled, the \"ConsumeInput\" option will also be enabled.\n\nThis option defaults to false.\n\nSee \"The LimitOutput option\" for a discussion on why \"LimitOutput\" is needed and how to use\nit.\n\nHere is an example of using an optional parameter to override the default buffer size.\n\nmy ($i, $status) = new Compress::Raw::Zlib::Inflate( -Bufsize => 300 ) ;\n\n$status = $i->inflate($input, $output [,$eof])\nInflates the complete contents of $input and writes the uncompressed data to $output. The $input\nand $output parameters can either be scalars or scalar references.\n\nReturns \"ZOK\" if successful and \"ZSTREAMEND\" if the end of the compressed data has been\nsuccessfully reached.\n\nIf not successful $status will hold the *zlib* error code.\n\nIf the \"ConsumeInput\" option has been set to true when the \"Compress::Raw::Zlib::Inflate\" object\nis created, the $input parameter is modified by \"inflate\". On completion it will contain what\nremains of the input buffer after inflation. In practice, this means that when the return status\nis \"ZOK\" the $input parameter will contain an empty string, and when the return status is\n\"ZSTREAMEND\" the $input parameter will contains what (if anything) was stored in the input\nbuffer after the deflated data stream.\n\nThis feature is useful when processing a file format that encapsulates a compressed data stream\n(e.g. gzip, zip) and there is useful data immediately after the deflation stream.\n\nIf the \"AppendOutput\" option is set to true in the constructor for this object, the uncompressed\ndata will be appended to $output. If it is false, $output will be truncated before any\nuncompressed data is written to it.\n\nThe $eof parameter needs a bit of explanation.\n\nPrior to version 1.2.0, zlib assumed that there was at least one trailing byte immediately after\nthe compressed data stream when it was carrying out decompression. This normally isn't a problem\nbecause the majority of zlib applications guarantee that there will be data directly after the\ncompressed data stream. For example, both gzip (RFC 1950) and zip both define trailing data that\nfollows the compressed data stream.\n\nThe $eof parameter only needs to be used if all of the following conditions apply\n\n1    You are either using a copy of zlib that is older than version 1.2.0 or you want your\napplication code to be able to run with as many different versions of zlib as possible.\n\n2    You have set the \"WindowBits\" parameter to \"-MAXWBITS\" in the constructor for this object,\ni.e. you are uncompressing a raw deflated data stream (RFC 1951).\n\n3    There is no data immediately after the compressed data stream.\n\nIf all of these are the case, then you need to set the $eof parameter to true on the final call\n(and only the final call) to \"$i->inflate\".\n\nIf you have built this module with zlib >= 1.2.0, the $eof parameter is ignored. You can still\nset it if you want, but it won't be used behind the scenes.\n\n$status = $i->inflateSync($input)\nThis method can be used to attempt to recover good data from a compressed data stream that is\npartially corrupt. It scans $input until it reaches either a *full flush point* or the end of\nthe buffer.\n\nIf a *full flush point* is found, \"ZOK\" is returned and $input will be have all data up to the\nflush point removed. This data can then be passed to the \"$i->inflate\" method to be\nuncompressed.\n\nAny other return code means that a flush point was not found. If more data is available,\n\"inflateSync\" can be called repeatedly with more compressed data until the flush point is found.\n\nNote *full flush points* are not present by default in compressed data streams. They must have\nbeen added explicitly when the data stream was created by calling \"Compress::Deflate::flush\"\nwith \"ZFULLFLUSH\".\n\n$status = $i->inflateReset()\nThis method will reset the inflation object $i. It can be used when you are uncompressing\nmultiple data streams and want to use the same object to uncompress each of them.\n\nReturns \"ZOK\" if successful.\n\n$i->dictadler()\nReturns the adler32 value for the dictionary.\n\n$i->crc32()\nReturns the crc32 value for the uncompressed data to date.\n\nIf the \"CRC32\" option is not enabled in the constructor for this object, this method will always\nreturn 0;\n\n$i->adler32()\nReturns the adler32 value for the uncompressed data to date.\n\nIf the \"ADLER32\" option is not enabled in the constructor for this object, this method will\nalways return 0;\n\n$i->msg()\nReturns the last error message generated by zlib.\n\n$i->totalin()\nReturns the total number of bytes compressed bytes input to inflate.\n\n$i->totalout()\nReturns the total number of uncompressed bytes output from inflate.\n\n$d->getBufSize()\nReturns the buffer size used to carry out the decompression.\n\n#### Examples\n\nHere is an example of using \"inflate\".\n\nuse strict ;\nuse warnings ;\n\nuse Compress::Raw::Zlib;\n\nmy $x = new Compress::Raw::Zlib::Inflate()\nor die \"Cannot create a inflation stream\\n\" ;\n\nmy $input = '' ;\nbinmode STDIN;\nbinmode STDOUT;\n\nmy ($output, $status) ;\nwhile (read(STDIN, $input, 4096))\n{\n$status = $x->inflate($input, $output) ;\n\nprint $output ;\n\nlast if $status != ZOK ;\n}\n\ndie \"inflation failed\\n\"\nunless $status == ZSTREAMEND ;\n\nThe next example show how to use the \"LimitOutput\" option. Notice the use of two nested loops in\nthis case. The outer loop reads the data from the input source - STDIN and the inner loop\nrepeatedly calls \"inflate\" until $input is exhausted, we get an error, or the end of the stream\nis reached. One point worth remembering is by using the \"LimitOutput\" option you also get\n\"ConsumeInput\" set as well - this makes the code below much simpler.\n\nuse strict ;\nuse warnings ;\n\nuse Compress::Raw::Zlib;\n\nmy $x = new Compress::Raw::Zlib::Inflate(LimitOutput => 1)\nor die \"Cannot create a inflation stream\\n\" ;\n\nmy $input = '' ;\nbinmode STDIN;\nbinmode STDOUT;\n\nmy ($output, $status) ;\n\nOUTER:\nwhile (read(STDIN, $input, 4096))\n{\ndo\n{\n$status = $x->inflate($input, $output) ;\n\nprint $output ;\n\nlast OUTER\nunless $status == ZOK || $status == ZBUFERROR ;\n}\nwhile ($status == ZOK && length $input);\n}\n\ndie \"inflation failed\\n\"\nunless $status == ZSTREAMEND ;\n\n### CHECKSUM FUNCTIONS\n\nTwo functions are provided by *zlib* to calculate checksums. For the Perl interface, the order\nof the two parameters in both functions has been reversed. This allows both running checksums\nand one off calculations to be done.\n\n$crc = adler32($buffer [,$crc]) ;\n$crc = crc32($buffer [,$crc]) ;\n\nThe buffer parameters can either be a scalar or a scalar reference.\n\nIf the $crc parameters is \"undef\", the crc value will be reset.\n\nIf you have built this module with zlib 1.2.3 or better, two more CRC-related functions are\navailable.\n\n$crc = crc32combine($crc1, $crc2, $len2);\n$adler = adler32combine($adler1, $adler2, $len2);\n\nThese functions allow checksums to be merged. Refer to the *zlib* documentation for more\ndetails.\n\n### Misc\n\nmy $version = Compress::Raw::Zlib::zlibversion();\nReturns the version of the zlib library.\n\nmy $flags = Compress::Raw::Zlib::zlibCompileFlags();\nReturns the flags indicating compile-time options that were used to build the zlib library. See\nthe zlib documentation for a description of the flags returned by \"zlibCompileFlags\".\n\nNote that when the zlib sources are built along with this module the \"sprintf\" flags (bits 24,\n25 and 26) should be ignored.\n\nIf you are using zlib 1.2.0 or older, \"zlibCompileFlags\" will return 0.\n\nThe LimitOutput option.\nBy default \"$i->inflate($input, $output)\" will uncompress *all* data in $input and write *all*\nof the uncompressed data it has generated to $output. This makes the interface to \"inflate\" much\nsimpler - if the method has uncompressed $input successfully *all* compressed data in $input\nwill have been dealt with. So if you are reading from an input source and uncompressing as you\ngo the code will look something like this\n\nuse strict ;\nuse warnings ;\n\nuse Compress::Raw::Zlib;\n\nmy $x = new Compress::Raw::Zlib::Inflate()\nor die \"Cannot create a inflation stream\\n\" ;\n\nmy $input = '' ;\n\nmy ($output, $status) ;\nwhile (read(STDIN, $input, 4096))\n{\n$status = $x->inflate($input, $output) ;\n\nprint $output ;\n\nlast if $status != ZOK ;\n}\n\ndie \"inflation failed\\n\"\nunless $status == ZSTREAMEND ;\n\nThe points to note are\n\n*    The main processing loop in the code handles reading of compressed data from STDIN.\n\n*    The status code returned from \"inflate\" will only trigger termination of the main\nprocessing loop if it isn't \"ZOK\". When \"LimitOutput\" has not been used the \"ZOK\" status\nmeans that the end of the compressed data stream has been reached or there has been an\nerror in uncompression.\n\n*    After the call to \"inflate\" *all* of the uncompressed data in $input will have been\nprocessed. This means the subsequent call to \"read\" can overwrite it's contents without any\nproblem.\n\nFor most use-cases the behavior described above is acceptable (this module and it's predecessor,\n\"Compress::Zlib\", have used it for over 10 years without an issue), but in a few very specific\nuse-cases the amount of memory required for $output can prohibitively large. For example, if the\ncompressed data stream contains the same pattern repeated thousands of times, a relatively small\ncompressed data stream can uncompress into hundreds of megabytes. Remember \"inflate\" will keep\nallocating memory until *all* the uncompressed data has been written to the output buffer - the\nsize of $output is unbounded.\n\nThe \"LimitOutput\" option is designed to help with this use-case.\n\nThe main difference in your code when using \"LimitOutput\" is having to deal with cases where the\n$input parameter still contains some uncompressed data that \"inflate\" hasn't processed yet. The\nstatus code returned from \"inflate\" will be \"ZOK\" if uncompression took place and \"ZBUFERROR\"\nif the output buffer is full.\n\nBelow is typical code that shows how to use \"LimitOutput\".\n\nuse strict ;\nuse warnings ;\n\nuse Compress::Raw::Zlib;\n\nmy $x = new Compress::Raw::Zlib::Inflate(LimitOutput => 1)\nor die \"Cannot create a inflation stream\\n\" ;\n\nmy $input = '' ;\nbinmode STDIN;\nbinmode STDOUT;\n\nmy ($output, $status) ;\n\nOUTER:\nwhile (read(STDIN, $input, 4096))\n{\ndo\n{\n$status = $x->inflate($input, $output) ;\n\nprint $output ;\n\nlast OUTER\nunless $status == ZOK || $status == ZBUFERROR ;\n}\nwhile ($status == ZOK && length $input);\n}\n\ndie \"inflation failed\\n\"\nunless $status == ZSTREAMEND ;\n\nPoints to note this time:\n\n*    There are now two nested loops in the code: the outer loop for reading the compressed data\nfrom STDIN, as before; and the inner loop to carry out the uncompression.\n\n*    There are two exit points from the inner uncompression loop.\n\nFirstly when \"inflate\" has returned a status other than \"ZOK\" or \"ZBUFERROR\". This means\nthat either the end of the compressed data stream has been reached (\"ZSTREAMEND\") or\nthere is an error in the compressed data. In either of these cases there is no point in\ncontinuing with reading the compressed data, so both loops are terminated.\n\nThe second exit point tests if there is any data left in the input buffer, $input -\nremember that the \"ConsumeInput\" option is automatically enabled when \"LimitOutput\" is\nused. When the input buffer has been exhausted, the outer loop can run again and overwrite\na now empty $input.\n\n### ACCESSING ZIP FILES\n\nAlthough it is possible (with some effort on your part) to use this module to access .zip files,\nthere are other perl modules available that will do all the hard work for you. Check out\n\"Archive::Zip\", \"Archive::Zip::SimpleZip\", \"IO::Compress::Zip\" and \"IO::Uncompress::Unzip\".\n\n### FAQ\n\nCompatibility with Unix compress/uncompress.\nThis module is not compatible with Unix \"compress\".\n\nIf you have the \"uncompress\" program available, you can use this to read compressed files\n\nopen F, \"uncompress -c $filename |\";\nwhile (<F>)\n{\n...\n\nAlternatively, if you have the \"gunzip\" program available, you can use this to read compressed\nfiles\n\nopen F, \"gunzip -c $filename |\";\nwhile (<F>)\n{\n...\n\nand this to write compress files, if you have the \"compress\" program available\n\nopen F, \"| compress -c $filename \";\nprint F \"data\";\n...\nclose F ;\n\n#### Accessing .tar.Z files\n\nSee previous FAQ item.\n\nIf the \"Archive::Tar\" module is installed and either the \"uncompress\" or \"gunzip\" programs are\navailable, you can use one of these workarounds to read \".tar.Z\" files.\n\nFirstly with \"uncompress\"\n\nuse strict;\nuse warnings;\nuse Archive::Tar;\n\nopen F, \"uncompress -c $filename |\";\nmy $tar = Archive::Tar->new(*F);\n...\n\nand this with \"gunzip\"\n\nuse strict;\nuse warnings;\nuse Archive::Tar;\n\nopen F, \"gunzip -c $filename |\";\nmy $tar = Archive::Tar->new(*F);\n...\n\nSimilarly, if the \"compress\" program is available, you can use this to write a \".tar.Z\" file\n\nuse strict;\nuse warnings;\nuse Archive::Tar;\nuse IO::File;\n\nmy $fh = new IO::File \"| compress -c >$filename\";\nmy $tar = Archive::Tar->new();\n...\n$tar->write($fh);\n$fh->close ;\n\n#### Zlib Library Version Support\n\nBy default \"Compress::Raw::Zlib\" will build with a private copy of version 1.2.5 of the zlib\nlibrary. (See the README file for details of how to override this behaviour)\n\nIf you decide to use a different version of the zlib library, you need to be aware of the\nfollowing issues\n\n*    First off, you must have zlib 1.0.5 or better.\n\n*    You need to have zlib 1.2.1 or better if you want to use the \"-Merge\" option with\n\"IO::Compress::Gzip\", \"IO::Compress::Deflate\" and \"IO::Compress::RawDeflate\".\n\n### CONSTANTS\n\nAll the *zlib* constants are automatically imported when you make use of *Compress::Raw::Zlib*.\n\n### SUPPORT\n\nGeneral feedback/questions/bug reports should be sent to\n<https://github.com/pmqs/Compress-Raw-Zlib/issues> (preferred) or\n<https://rt.cpan.org/Public/Dist/Display.html?Name=Compress-Raw-Zlib>.\n\n### SEE ALSO\n\nCompress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Compress::Deflate,\nIO::Uncompress::Inflate, IO::Compress::RawDeflate, IO::Uncompress::RawInflate,\nIO::Compress::Bzip2, IO::Uncompress::Bunzip2, IO::Compress::Lzma, IO::Uncompress::UnLzma,\nIO::Compress::Xz, IO::Uncompress::UnXz, IO::Compress::Lzip, IO::Uncompress::UnLzip,\nIO::Compress::Lzop, IO::Uncompress::UnLzop, IO::Compress::Lzf, IO::Uncompress::UnLzf,\nIO::Compress::Zstd, IO::Uncompress::UnZstd, IO::Uncompress::AnyInflate,\nIO::Uncompress::AnyUncompress\n\nIO::Compress::FAQ\n\nFile::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib\n\nFor RFC 1950, 1951 and 1952 see <http://www.faqs.org/rfcs/rfc1950.html>,\n<http://www.faqs.org/rfcs/rfc1951.html> and <http://www.faqs.org/rfcs/rfc1952.html>\n\nThe *zlib* compression library was written by Jean-loup Gailly \"gzip@prep.ai.mit.edu\" and Mark\nAdler \"madler@alumni.caltech.edu\".\n\nThe primary site for the *zlib* compression library is <http://www.zlib.org>.\n\nThe primary site for gzip is <http://www.gzip.org>.\n\n### AUTHOR\n\nThis module was written by Paul Marquess, \"pmqs@cpan.org\".\n\n### MODIFICATION HISTORY\n\nSee the Changes file.\n\n### COPYRIGHT AND LICENSE\n\nCopyright (c) 2005-2021 Paul Marquess. All rights reserved.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\n"
        }
    ],
    "structuredContent": {
        "command": "Compress::Raw::Zlib",
        "section": "",
        "mode": "perldoc",
        "summary": "Compress::Raw::Zlib - Low-Level Interface to zlib compression library",
        "synopsis": "use Compress::Raw::Zlib ;\n($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] ) ;\n$status = $d->deflate($input, $output) ;\n$status = $d->flush($output [, $flushtype]) ;\n$d->deflateReset() ;\n$d->deflateParams(OPTS) ;\n$d->deflateTune(OPTS) ;\n$d->dictadler() ;\n$d->crc32() ;\n$d->adler32() ;\n$d->totalin() ;\n$d->totalout() ;\n$d->msg() ;\n$d->getStrategy();\n$d->getLevel();\n$d->getBufSize();\n($i, $status) = new Compress::Raw::Zlib::Inflate( [OPT] ) ;\n$status = $i->inflate($input, $output [, $eof]) ;\n$status = $i->inflateSync($input) ;\n$i->inflateReset() ;\n$i->dictadler() ;\n$d->crc32() ;\n$d->adler32() ;\n$i->totalin() ;\n$i->totalout() ;\n$i->msg() ;\n$d->getBufSize();\n$crc = adler32($buffer [,$crc]) ;\n$crc = crc32($buffer [,$crc]) ;\n$crc = crc32combine($crc1, $crc2, $len2);\n$adler = adler32combine($adler1, $adler2, $len2);\nmy $version = Compress::Raw::Zlib::zlibversion();\nmy $flags = Compress::Raw::Zlib::zlibCompileFlags();",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 39,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "Compress::Raw::Zlib::Deflate",
                "lines": 26,
                "subsections": [
                    {
                        "name": "-Level",
                        "lines": 5
                    },
                    {
                        "name": "-Method",
                        "lines": 3
                    },
                    {
                        "name": "-WindowBits",
                        "lines": 12
                    },
                    {
                        "name": "-MemLevel",
                        "lines": 5
                    },
                    {
                        "name": "-Strategy",
                        "lines": 5
                    },
                    {
                        "name": "-Dictionary",
                        "lines": 6
                    },
                    {
                        "name": "-Bufsize",
                        "lines": 6
                    },
                    {
                        "name": "-AppendOutput",
                        "lines": 11
                    },
                    {
                        "name": "-CRC32",
                        "lines": 5
                    },
                    {
                        "name": "-ADLER32",
                        "lines": 63
                    },
                    {
                        "name": "-Level",
                        "lines": 3
                    },
                    {
                        "name": "-Strategy",
                        "lines": 3
                    },
                    {
                        "name": "-BufSize",
                        "lines": 41
                    },
                    {
                        "name": "Example",
                        "lines": 31
                    }
                ]
            },
            {
                "name": "Compress::Raw::Zlib::Inflate",
                "lines": 24,
                "subsections": [
                    {
                        "name": "-WindowBits",
                        "lines": 15
                    },
                    {
                        "name": "-Bufsize",
                        "lines": 6
                    },
                    {
                        "name": "-Dictionary",
                        "lines": 2
                    },
                    {
                        "name": "-AppendOutput",
                        "lines": 10
                    },
                    {
                        "name": "-CRC32",
                        "lines": 5
                    },
                    {
                        "name": "-ADLER32",
                        "lines": 5
                    },
                    {
                        "name": "-ConsumeInput",
                        "lines": 9
                    },
                    {
                        "name": "-LimitOutput",
                        "lines": 118
                    },
                    {
                        "name": "Examples",
                        "lines": 65
                    }
                ]
            },
            {
                "name": "CHECKSUM FUNCTIONS",
                "lines": 20,
                "subsections": []
            },
            {
                "name": "Misc",
                "lines": 121,
                "subsections": []
            },
            {
                "name": "ACCESSING ZIP FILES",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "FAQ",
                "lines": 25,
                "subsections": [
                    {
                        "name": "Accessing .tar.Z files",
                        "lines": 38
                    },
                    {
                        "name": "Zlib Library Version Support",
                        "lines": 11
                    }
                ]
            },
            {
                "name": "CONSTANTS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SUPPORT",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 22,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "MODIFICATION HISTORY",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Compress::Raw::Zlib - Low-Level Interface to zlib compression library\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Compress::Raw::Zlib ;\n\n($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] ) ;\n$status = $d->deflate($input, $output) ;\n$status = $d->flush($output [, $flushtype]) ;\n$d->deflateReset() ;\n$d->deflateParams(OPTS) ;\n$d->deflateTune(OPTS) ;\n$d->dictadler() ;\n$d->crc32() ;\n$d->adler32() ;\n$d->totalin() ;\n$d->totalout() ;\n$d->msg() ;\n$d->getStrategy();\n$d->getLevel();\n$d->getBufSize();\n\n($i, $status) = new Compress::Raw::Zlib::Inflate( [OPT] ) ;\n$status = $i->inflate($input, $output [, $eof]) ;\n$status = $i->inflateSync($input) ;\n$i->inflateReset() ;\n$i->dictadler() ;\n$d->crc32() ;\n$d->adler32() ;\n$i->totalin() ;\n$i->totalout() ;\n$i->msg() ;\n$d->getBufSize();\n\n$crc = adler32($buffer [,$crc]) ;\n$crc = crc32($buffer [,$crc]) ;\n\n$crc = crc32combine($crc1, $crc2, $len2);\n$adler = adler32combine($adler1, $adler2, $len2);\n\nmy $version = Compress::Raw::Zlib::zlibversion();\nmy $flags = Compress::Raw::Zlib::zlibCompileFlags();\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The *Compress::Raw::Zlib* module provides a Perl interface to the *zlib* compression library\n(see \"AUTHOR\" for details about where to get *zlib*).\n",
                "subsections": []
            },
            "Compress::Raw::Zlib::Deflate": {
                "content": "This section defines an interface that allows in-memory compression using the *deflate*\ninterface provided by zlib.\n\nHere is a definition of the interface available:\n\n($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] )\nInitialises a deflation object.\n\nIf you are familiar with the *zlib* library, it combines the features of the *zlib* functions\n\"deflateInit\", \"deflateInit2\" and \"deflateSetDictionary\".\n\nIf successful, it will return the initialised deflation object, $d and a $status of \"ZOK\" in a\nlist context. In scalar context it returns the deflation object, $d, only.\n\nIf not successful, the returned deflation object, $d, will be *undef* and $status will hold the\na *zlib* error code.\n\nThe function optionally takes a number of named options specified as \"Name => value\" pairs. This\nallows individual options to be tailored without having to specify them all in the parameter\nlist.\n\nFor backward compatibility, it is also possible to pass the parameters as a reference to a hash\ncontaining the name=>value pairs.\n\nBelow is a list of the valid options:\n",
                "subsections": [
                    {
                        "name": "-Level",
                        "content": "Defines the compression level. Valid values are 0 through 9, \"ZNOCOMPRESSION\",\n\"ZBESTSPEED\", \"ZBESTCOMPRESSION\", and \"ZDEFAULTCOMPRESSION\".\n\nThe default is \"ZDEFAULTCOMPRESSION\".\n"
                    },
                    {
                        "name": "-Method",
                        "content": "Defines the compression method. The only valid value at present (and the default) is\n\"ZDEFLATED\".\n"
                    },
                    {
                        "name": "-WindowBits",
                        "content": "To compress an RFC 1950 data stream, set \"WindowBits\" to a positive number between 8 and\n15.\n\nTo compress an RFC 1951 data stream, set \"WindowBits\" to \"-MAXWBITS\".\n\nTo compress an RFC 1952 data stream (i.e. gzip), set \"WindowBits\" to \"WANTGZIP\".\n\nFor a definition of the meaning and valid values for \"WindowBits\" refer to the *zlib*\ndocumentation for *deflateInit2*.\n\nDefaults to \"MAXWBITS\".\n"
                    },
                    {
                        "name": "-MemLevel",
                        "content": "For a definition of the meaning and valid values for \"MemLevel\" refer to the *zlib*\ndocumentation for *deflateInit2*.\n\nDefaults to MAXMEMLEVEL.\n"
                    },
                    {
                        "name": "-Strategy",
                        "content": "Defines the strategy used to tune the compression. The valid values are\n\"ZDEFAULTSTRATEGY\", \"ZFILTERED\", \"ZRLE\", \"ZFIXED\" and \"ZHUFFMANONLY\".\n\nThe default is \"ZDEFAULTSTRATEGY\".\n"
                    },
                    {
                        "name": "-Dictionary",
                        "content": "When a dictionary is specified *Compress::Raw::Zlib* will automatically call\n\"deflateSetDictionary\" directly after calling \"deflateInit\". The Adler32 value for the\ndictionary can be obtained by calling the method \"$d->dictadler()\".\n\nThe default is no dictionary.\n"
                    },
                    {
                        "name": "-Bufsize",
                        "content": "Sets the initial size for the output buffer used by the \"$d->deflate\" and \"$d->flush\"\nmethods. If the buffer has to be reallocated to increase the size, it will grow in\nincrements of \"Bufsize\".\n\nThe default buffer size is 4096.\n"
                    },
                    {
                        "name": "-AppendOutput",
                        "content": "This option controls how data is written to the output buffer by the \"$d->deflate\" and\n\"$d->flush\" methods.\n\nIf the \"AppendOutput\" option is set to false, the output buffers in the \"$d->deflate\" and\n\"$d->flush\" methods will be truncated before uncompressed data is written to them.\n\nIf the option is set to true, uncompressed data will be appended to the output buffer in\nthe \"$d->deflate\" and \"$d->flush\" methods.\n\nThis option defaults to false.\n"
                    },
                    {
                        "name": "-CRC32",
                        "content": "If set to true, a crc32 checksum of the uncompressed data will be calculated. Use the\n\"$d->crc32\" method to retrieve this value.\n\nThis option defaults to false.\n"
                    },
                    {
                        "name": "-ADLER32",
                        "content": "If set to true, an adler32 checksum of the uncompressed data will be calculated. Use the\n\"$d->adler32\" method to retrieve this value.\n\nThis option defaults to false.\n\nHere is an example of using the \"Compress::Raw::Zlib::Deflate\" optional parameter list to\noverride the default buffer size and compression level. All other options will take their\ndefault values.\n\nmy $d = new Compress::Raw::Zlib::Deflate ( -Bufsize => 300,\n-Level   => ZBESTSPEED ) ;\n\n$status = $d->deflate($input, $output)\nDeflates the contents of $input and writes the compressed data to $output.\n\nThe $input and $output parameters can be either scalars or scalar references.\n\nWhen finished, $input will be completely processed (assuming there were no errors). If the\ndeflation was successful it writes the deflated data to $output and returns a status value of\n\"ZOK\".\n\nOn error, it returns a *zlib* error code.\n\nIf the \"AppendOutput\" option is set to true in the constructor for the $d object, the compressed\ndata will be appended to $output. If it is false, $output will be truncated before any\ncompressed data is written to it.\n\nNote: This method will not necessarily write compressed data to $output every time it is called.\nSo do not assume that there has been an error if the contents of $output is empty on returning\nfrom this method. As long as the return code from the method is \"ZOK\", the deflate has\nsucceeded.\n\n$status = $d->flush($output [, $flushtype])\nTypically used to finish the deflation. Any pending output will be written to $output.\n\nReturns \"ZOK\" if successful.\n\nNote that flushing can seriously degrade the compression ratio, so it should only be used to\nterminate a decompression (using \"ZFINISH\") or when you want to create a *full flush point*\n(using \"ZFULLFLUSH\").\n\nBy default the \"flushtype\" used is \"ZFINISH\". Other valid values for \"flushtype\" are\n\"ZNOFLUSH\", \"ZPARTIALFLUSH\", \"ZSYNCFLUSH\" and \"ZFULLFLUSH\". It is strongly recommended\nthat you only set the \"flushtype\" parameter if you fully understand the implications of what it\ndoes. See the \"zlib\" documentation for details.\n\nIf the \"AppendOutput\" option is set to true in the constructor for the $d object, the compressed\ndata will be appended to $output. If it is false, $output will be truncated before any\ncompressed data is written to it.\n\n$status = $d->deflateReset()\nThis method will reset the deflation object $d. It can be used when you are compressing multiple\ndata streams and want to use the same object to compress each of them. It should only be used\nonce the previous data stream has been flushed successfully, i.e. a call to\n\"$d->flush(ZFINISH)\" has returned \"ZOK\".\n\nReturns \"ZOK\" if successful.\n\n$status = $d->deflateParams([OPT])\nChange settings for the deflate object $d.\n\nThe list of the valid options is shown below. Options not specified will remain unchanged.\n"
                    },
                    {
                        "name": "-Level",
                        "content": "Defines the compression level. Valid values are 0 through 9, \"ZNOCOMPRESSION\",\n\"ZBESTSPEED\", \"ZBESTCOMPRESSION\", and \"ZDEFAULTCOMPRESSION\".\n"
                    },
                    {
                        "name": "-Strategy",
                        "content": "Defines the strategy used to tune the compression. The valid values are\n\"ZDEFAULTSTRATEGY\", \"ZFILTERED\" and \"ZHUFFMANONLY\".\n"
                    },
                    {
                        "name": "-BufSize",
                        "content": "Sets the initial size for the output buffer used by the \"$d->deflate\" and \"$d->flush\"\nmethods. If the buffer has to be reallocated to increase the size, it will grow in\nincrements of \"Bufsize\".\n\n$status = $d->deflateTune($goodlength, $maxlazy, $nicelength, $maxchain)\nTune the internal settings for the deflate object $d. This option is only available if you are\nrunning zlib 1.2.2.3 or better.\n\nRefer to the documentation in zlib.h for instructions on how to fly \"deflateTune\".\n\n$d->dictadler()\nReturns the adler32 value for the dictionary.\n\n$d->crc32()\nReturns the crc32 value for the uncompressed data to date.\n\nIf the \"CRC32\" option is not enabled in the constructor for this object, this method will always\nreturn 0;\n\n$d->adler32()\nReturns the adler32 value for the uncompressed data to date.\n\n$d->msg()\nReturns the last error message generated by zlib.\n\n$d->totalin()\nReturns the total number of bytes uncompressed bytes input to deflate.\n\n$d->totalout()\nReturns the total number of compressed bytes output from deflate.\n\n$d->getStrategy()\nReturns the deflation strategy currently used. Valid values are \"ZDEFAULTSTRATEGY\",\n\"ZFILTERED\" and \"ZHUFFMANONLY\".\n\n$d->getLevel()\nReturns the compression level being used.\n\n$d->getBufSize()\nReturns the buffer size used to carry out the compression.\n"
                    },
                    {
                        "name": "Example",
                        "content": "Here is a trivial example of using \"deflate\". It simply reads standard input, deflates it and\nwrites it to standard output.\n\nuse strict ;\nuse warnings ;\n\nuse Compress::Raw::Zlib ;\n\nbinmode STDIN;\nbinmode STDOUT;\nmy $x = new Compress::Raw::Zlib::Deflate\nor die \"Cannot create a deflation stream\\n\" ;\n\nmy ($output, $status) ;\nwhile (<>)\n{\n$status = $x->deflate($, $output) ;\n\n$status == ZOK\nor die \"deflation failed\\n\" ;\n\nprint $output ;\n}\n\n$status = $x->flush($output) ;\n\n$status == ZOK\nor die \"deflation failed\\n\" ;\n\nprint $output ;\n"
                    }
                ]
            },
            "Compress::Raw::Zlib::Inflate": {
                "content": "This section defines an interface that allows in-memory uncompression using the *inflate*\ninterface provided by zlib.\n\nHere is a definition of the interface:\n\n($i, $status) = new Compress::Raw::Zlib::Inflate( [OPT] )\nInitialises an inflation object.\n\nIn a list context it returns the inflation object, $i, and the *zlib* status code ($status). In\na scalar context it returns the inflation object only.\n\nIf successful, $i will hold the inflation object and $status will be \"ZOK\".\n\nIf not successful, $i will be *undef* and $status will hold the *zlib* error code.\n\nThe function optionally takes a number of named options specified as \"-Name => value\" pairs.\nThis allows individual options to be tailored without having to specify them all in the\nparameter list.\n\nFor backward compatibility, it is also possible to pass the parameters as a reference to a hash\ncontaining the \"name=>value\" pairs.\n\nHere is a list of the valid options:\n",
                "subsections": [
                    {
                        "name": "-WindowBits",
                        "content": "To uncompress an RFC 1950 data stream, set \"WindowBits\" to a positive number between 8 and\n15.\n\nTo uncompress an RFC 1951 data stream, set \"WindowBits\" to \"-MAXWBITS\".\n\nTo uncompress an RFC 1952 data stream (i.e. gzip), set \"WindowBits\" to \"WANTGZIP\".\n\nTo auto-detect and uncompress an RFC 1950 or RFC 1952 data stream (i.e. gzip), set\n\"WindowBits\" to \"WANTGZIPORZLIB\".\n\nFor a full definition of the meaning and valid values for \"WindowBits\" refer to the *zlib*\ndocumentation for *inflateInit2*.\n\nDefaults to \"MAXWBITS\".\n"
                    },
                    {
                        "name": "-Bufsize",
                        "content": "Sets the initial size for the output buffer used by the \"$i->inflate\" method. If the output\nbuffer in this method has to be reallocated to increase the size, it will grow in\nincrements of \"Bufsize\".\n\nDefault is 4096.\n"
                    },
                    {
                        "name": "-Dictionary",
                        "content": "The default is no dictionary.\n"
                    },
                    {
                        "name": "-AppendOutput",
                        "content": "This option controls how data is written to the output buffer by the \"$i->inflate\" method.\n\nIf the option is set to false, the output buffer in the \"$i->inflate\" method will be\ntruncated before uncompressed data is written to it.\n\nIf the option is set to true, uncompressed data will be appended to the output buffer by\nthe \"$i->inflate\" method.\n\nThis option defaults to false.\n"
                    },
                    {
                        "name": "-CRC32",
                        "content": "If set to true, a crc32 checksum of the uncompressed data will be calculated. Use the\n\"$i->crc32\" method to retrieve this value.\n\nThis option defaults to false.\n"
                    },
                    {
                        "name": "-ADLER32",
                        "content": "If set to true, an adler32 checksum of the uncompressed data will be calculated. Use the\n\"$i->adler32\" method to retrieve this value.\n\nThis option defaults to false.\n"
                    },
                    {
                        "name": "-ConsumeInput",
                        "content": "If set to true, this option will remove compressed data from the input buffer of the\n\"$i->inflate\" method as the inflate progresses.\n\nThis option can be useful when you are processing compressed data that is embedded in\nanother file/buffer. In this case the data that immediately follows the compressed stream\nwill be left in the input buffer.\n\nThis option defaults to true.\n"
                    },
                    {
                        "name": "-LimitOutput",
                        "content": "The \"LimitOutput\" option changes the behavior of the \"$i->inflate\" method so that the\namount of memory used by the output buffer can be limited.\n\nWhen \"LimitOutput\" is used the size of the output buffer used will either be the value of\nthe \"Bufsize\" option or the amount of memory already allocated to $output, whichever is\nlarger. Predicting the output size available is tricky, so don't rely on getting an exact\noutput buffer size.\n\nWhen \"LimitOutout\" is not specified \"$i->inflate\" will use as much memory as it takes to\nwrite all the uncompressed data it creates by uncompressing the input buffer.\n\nIf \"LimitOutput\" is enabled, the \"ConsumeInput\" option will also be enabled.\n\nThis option defaults to false.\n\nSee \"The LimitOutput option\" for a discussion on why \"LimitOutput\" is needed and how to use\nit.\n\nHere is an example of using an optional parameter to override the default buffer size.\n\nmy ($i, $status) = new Compress::Raw::Zlib::Inflate( -Bufsize => 300 ) ;\n\n$status = $i->inflate($input, $output [,$eof])\nInflates the complete contents of $input and writes the uncompressed data to $output. The $input\nand $output parameters can either be scalars or scalar references.\n\nReturns \"ZOK\" if successful and \"ZSTREAMEND\" if the end of the compressed data has been\nsuccessfully reached.\n\nIf not successful $status will hold the *zlib* error code.\n\nIf the \"ConsumeInput\" option has been set to true when the \"Compress::Raw::Zlib::Inflate\" object\nis created, the $input parameter is modified by \"inflate\". On completion it will contain what\nremains of the input buffer after inflation. In practice, this means that when the return status\nis \"ZOK\" the $input parameter will contain an empty string, and when the return status is\n\"ZSTREAMEND\" the $input parameter will contains what (if anything) was stored in the input\nbuffer after the deflated data stream.\n\nThis feature is useful when processing a file format that encapsulates a compressed data stream\n(e.g. gzip, zip) and there is useful data immediately after the deflation stream.\n\nIf the \"AppendOutput\" option is set to true in the constructor for this object, the uncompressed\ndata will be appended to $output. If it is false, $output will be truncated before any\nuncompressed data is written to it.\n\nThe $eof parameter needs a bit of explanation.\n\nPrior to version 1.2.0, zlib assumed that there was at least one trailing byte immediately after\nthe compressed data stream when it was carrying out decompression. This normally isn't a problem\nbecause the majority of zlib applications guarantee that there will be data directly after the\ncompressed data stream. For example, both gzip (RFC 1950) and zip both define trailing data that\nfollows the compressed data stream.\n\nThe $eof parameter only needs to be used if all of the following conditions apply\n\n1    You are either using a copy of zlib that is older than version 1.2.0 or you want your\napplication code to be able to run with as many different versions of zlib as possible.\n\n2    You have set the \"WindowBits\" parameter to \"-MAXWBITS\" in the constructor for this object,\ni.e. you are uncompressing a raw deflated data stream (RFC 1951).\n\n3    There is no data immediately after the compressed data stream.\n\nIf all of these are the case, then you need to set the $eof parameter to true on the final call\n(and only the final call) to \"$i->inflate\".\n\nIf you have built this module with zlib >= 1.2.0, the $eof parameter is ignored. You can still\nset it if you want, but it won't be used behind the scenes.\n\n$status = $i->inflateSync($input)\nThis method can be used to attempt to recover good data from a compressed data stream that is\npartially corrupt. It scans $input until it reaches either a *full flush point* or the end of\nthe buffer.\n\nIf a *full flush point* is found, \"ZOK\" is returned and $input will be have all data up to the\nflush point removed. This data can then be passed to the \"$i->inflate\" method to be\nuncompressed.\n\nAny other return code means that a flush point was not found. If more data is available,\n\"inflateSync\" can be called repeatedly with more compressed data until the flush point is found.\n\nNote *full flush points* are not present by default in compressed data streams. They must have\nbeen added explicitly when the data stream was created by calling \"Compress::Deflate::flush\"\nwith \"ZFULLFLUSH\".\n\n$status = $i->inflateReset()\nThis method will reset the inflation object $i. It can be used when you are uncompressing\nmultiple data streams and want to use the same object to uncompress each of them.\n\nReturns \"ZOK\" if successful.\n\n$i->dictadler()\nReturns the adler32 value for the dictionary.\n\n$i->crc32()\nReturns the crc32 value for the uncompressed data to date.\n\nIf the \"CRC32\" option is not enabled in the constructor for this object, this method will always\nreturn 0;\n\n$i->adler32()\nReturns the adler32 value for the uncompressed data to date.\n\nIf the \"ADLER32\" option is not enabled in the constructor for this object, this method will\nalways return 0;\n\n$i->msg()\nReturns the last error message generated by zlib.\n\n$i->totalin()\nReturns the total number of bytes compressed bytes input to inflate.\n\n$i->totalout()\nReturns the total number of uncompressed bytes output from inflate.\n\n$d->getBufSize()\nReturns the buffer size used to carry out the decompression.\n"
                    },
                    {
                        "name": "Examples",
                        "content": "Here is an example of using \"inflate\".\n\nuse strict ;\nuse warnings ;\n\nuse Compress::Raw::Zlib;\n\nmy $x = new Compress::Raw::Zlib::Inflate()\nor die \"Cannot create a inflation stream\\n\" ;\n\nmy $input = '' ;\nbinmode STDIN;\nbinmode STDOUT;\n\nmy ($output, $status) ;\nwhile (read(STDIN, $input, 4096))\n{\n$status = $x->inflate($input, $output) ;\n\nprint $output ;\n\nlast if $status != ZOK ;\n}\n\ndie \"inflation failed\\n\"\nunless $status == ZSTREAMEND ;\n\nThe next example show how to use the \"LimitOutput\" option. Notice the use of two nested loops in\nthis case. The outer loop reads the data from the input source - STDIN and the inner loop\nrepeatedly calls \"inflate\" until $input is exhausted, we get an error, or the end of the stream\nis reached. One point worth remembering is by using the \"LimitOutput\" option you also get\n\"ConsumeInput\" set as well - this makes the code below much simpler.\n\nuse strict ;\nuse warnings ;\n\nuse Compress::Raw::Zlib;\n\nmy $x = new Compress::Raw::Zlib::Inflate(LimitOutput => 1)\nor die \"Cannot create a inflation stream\\n\" ;\n\nmy $input = '' ;\nbinmode STDIN;\nbinmode STDOUT;\n\nmy ($output, $status) ;\n\nOUTER:\nwhile (read(STDIN, $input, 4096))\n{\ndo\n{\n$status = $x->inflate($input, $output) ;\n\nprint $output ;\n\nlast OUTER\nunless $status == ZOK || $status == ZBUFERROR ;\n}\nwhile ($status == ZOK && length $input);\n}\n\ndie \"inflation failed\\n\"\nunless $status == ZSTREAMEND ;\n"
                    }
                ]
            },
            "CHECKSUM FUNCTIONS": {
                "content": "Two functions are provided by *zlib* to calculate checksums. For the Perl interface, the order\nof the two parameters in both functions has been reversed. This allows both running checksums\nand one off calculations to be done.\n\n$crc = adler32($buffer [,$crc]) ;\n$crc = crc32($buffer [,$crc]) ;\n\nThe buffer parameters can either be a scalar or a scalar reference.\n\nIf the $crc parameters is \"undef\", the crc value will be reset.\n\nIf you have built this module with zlib 1.2.3 or better, two more CRC-related functions are\navailable.\n\n$crc = crc32combine($crc1, $crc2, $len2);\n$adler = adler32combine($adler1, $adler2, $len2);\n\nThese functions allow checksums to be merged. Refer to the *zlib* documentation for more\ndetails.\n",
                "subsections": []
            },
            "Misc": {
                "content": "my $version = Compress::Raw::Zlib::zlibversion();\nReturns the version of the zlib library.\n\nmy $flags = Compress::Raw::Zlib::zlibCompileFlags();\nReturns the flags indicating compile-time options that were used to build the zlib library. See\nthe zlib documentation for a description of the flags returned by \"zlibCompileFlags\".\n\nNote that when the zlib sources are built along with this module the \"sprintf\" flags (bits 24,\n25 and 26) should be ignored.\n\nIf you are using zlib 1.2.0 or older, \"zlibCompileFlags\" will return 0.\n\nThe LimitOutput option.\nBy default \"$i->inflate($input, $output)\" will uncompress *all* data in $input and write *all*\nof the uncompressed data it has generated to $output. This makes the interface to \"inflate\" much\nsimpler - if the method has uncompressed $input successfully *all* compressed data in $input\nwill have been dealt with. So if you are reading from an input source and uncompressing as you\ngo the code will look something like this\n\nuse strict ;\nuse warnings ;\n\nuse Compress::Raw::Zlib;\n\nmy $x = new Compress::Raw::Zlib::Inflate()\nor die \"Cannot create a inflation stream\\n\" ;\n\nmy $input = '' ;\n\nmy ($output, $status) ;\nwhile (read(STDIN, $input, 4096))\n{\n$status = $x->inflate($input, $output) ;\n\nprint $output ;\n\nlast if $status != ZOK ;\n}\n\ndie \"inflation failed\\n\"\nunless $status == ZSTREAMEND ;\n\nThe points to note are\n\n*    The main processing loop in the code handles reading of compressed data from STDIN.\n\n*    The status code returned from \"inflate\" will only trigger termination of the main\nprocessing loop if it isn't \"ZOK\". When \"LimitOutput\" has not been used the \"ZOK\" status\nmeans that the end of the compressed data stream has been reached or there has been an\nerror in uncompression.\n\n*    After the call to \"inflate\" *all* of the uncompressed data in $input will have been\nprocessed. This means the subsequent call to \"read\" can overwrite it's contents without any\nproblem.\n\nFor most use-cases the behavior described above is acceptable (this module and it's predecessor,\n\"Compress::Zlib\", have used it for over 10 years without an issue), but in a few very specific\nuse-cases the amount of memory required for $output can prohibitively large. For example, if the\ncompressed data stream contains the same pattern repeated thousands of times, a relatively small\ncompressed data stream can uncompress into hundreds of megabytes. Remember \"inflate\" will keep\nallocating memory until *all* the uncompressed data has been written to the output buffer - the\nsize of $output is unbounded.\n\nThe \"LimitOutput\" option is designed to help with this use-case.\n\nThe main difference in your code when using \"LimitOutput\" is having to deal with cases where the\n$input parameter still contains some uncompressed data that \"inflate\" hasn't processed yet. The\nstatus code returned from \"inflate\" will be \"ZOK\" if uncompression took place and \"ZBUFERROR\"\nif the output buffer is full.\n\nBelow is typical code that shows how to use \"LimitOutput\".\n\nuse strict ;\nuse warnings ;\n\nuse Compress::Raw::Zlib;\n\nmy $x = new Compress::Raw::Zlib::Inflate(LimitOutput => 1)\nor die \"Cannot create a inflation stream\\n\" ;\n\nmy $input = '' ;\nbinmode STDIN;\nbinmode STDOUT;\n\nmy ($output, $status) ;\n\nOUTER:\nwhile (read(STDIN, $input, 4096))\n{\ndo\n{\n$status = $x->inflate($input, $output) ;\n\nprint $output ;\n\nlast OUTER\nunless $status == ZOK || $status == ZBUFERROR ;\n}\nwhile ($status == ZOK && length $input);\n}\n\ndie \"inflation failed\\n\"\nunless $status == ZSTREAMEND ;\n\nPoints to note this time:\n\n*    There are now two nested loops in the code: the outer loop for reading the compressed data\nfrom STDIN, as before; and the inner loop to carry out the uncompression.\n\n*    There are two exit points from the inner uncompression loop.\n\nFirstly when \"inflate\" has returned a status other than \"ZOK\" or \"ZBUFERROR\". This means\nthat either the end of the compressed data stream has been reached (\"ZSTREAMEND\") or\nthere is an error in the compressed data. In either of these cases there is no point in\ncontinuing with reading the compressed data, so both loops are terminated.\n\nThe second exit point tests if there is any data left in the input buffer, $input -\nremember that the \"ConsumeInput\" option is automatically enabled when \"LimitOutput\" is\nused. When the input buffer has been exhausted, the outer loop can run again and overwrite\na now empty $input.\n",
                "subsections": []
            },
            "ACCESSING ZIP FILES": {
                "content": "Although it is possible (with some effort on your part) to use this module to access .zip files,\nthere are other perl modules available that will do all the hard work for you. Check out\n\"Archive::Zip\", \"Archive::Zip::SimpleZip\", \"IO::Compress::Zip\" and \"IO::Uncompress::Unzip\".\n",
                "subsections": []
            },
            "FAQ": {
                "content": "Compatibility with Unix compress/uncompress.\nThis module is not compatible with Unix \"compress\".\n\nIf you have the \"uncompress\" program available, you can use this to read compressed files\n\nopen F, \"uncompress -c $filename |\";\nwhile (<F>)\n{\n...\n\nAlternatively, if you have the \"gunzip\" program available, you can use this to read compressed\nfiles\n\nopen F, \"gunzip -c $filename |\";\nwhile (<F>)\n{\n...\n\nand this to write compress files, if you have the \"compress\" program available\n\nopen F, \"| compress -c $filename \";\nprint F \"data\";\n...\nclose F ;\n",
                "subsections": [
                    {
                        "name": "Accessing .tar.Z files",
                        "content": "See previous FAQ item.\n\nIf the \"Archive::Tar\" module is installed and either the \"uncompress\" or \"gunzip\" programs are\navailable, you can use one of these workarounds to read \".tar.Z\" files.\n\nFirstly with \"uncompress\"\n\nuse strict;\nuse warnings;\nuse Archive::Tar;\n\nopen F, \"uncompress -c $filename |\";\nmy $tar = Archive::Tar->new(*F);\n...\n\nand this with \"gunzip\"\n\nuse strict;\nuse warnings;\nuse Archive::Tar;\n\nopen F, \"gunzip -c $filename |\";\nmy $tar = Archive::Tar->new(*F);\n...\n\nSimilarly, if the \"compress\" program is available, you can use this to write a \".tar.Z\" file\n\nuse strict;\nuse warnings;\nuse Archive::Tar;\nuse IO::File;\n\nmy $fh = new IO::File \"| compress -c >$filename\";\nmy $tar = Archive::Tar->new();\n...\n$tar->write($fh);\n$fh->close ;\n"
                    },
                    {
                        "name": "Zlib Library Version Support",
                        "content": "By default \"Compress::Raw::Zlib\" will build with a private copy of version 1.2.5 of the zlib\nlibrary. (See the README file for details of how to override this behaviour)\n\nIf you decide to use a different version of the zlib library, you need to be aware of the\nfollowing issues\n\n*    First off, you must have zlib 1.0.5 or better.\n\n*    You need to have zlib 1.2.1 or better if you want to use the \"-Merge\" option with\n\"IO::Compress::Gzip\", \"IO::Compress::Deflate\" and \"IO::Compress::RawDeflate\".\n"
                    }
                ]
            },
            "CONSTANTS": {
                "content": "All the *zlib* constants are automatically imported when you make use of *Compress::Raw::Zlib*.\n",
                "subsections": []
            },
            "SUPPORT": {
                "content": "General feedback/questions/bug reports should be sent to\n<https://github.com/pmqs/Compress-Raw-Zlib/issues> (preferred) or\n<https://rt.cpan.org/Public/Dist/Display.html?Name=Compress-Raw-Zlib>.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Compress::Deflate,\nIO::Uncompress::Inflate, IO::Compress::RawDeflate, IO::Uncompress::RawInflate,\nIO::Compress::Bzip2, IO::Uncompress::Bunzip2, IO::Compress::Lzma, IO::Uncompress::UnLzma,\nIO::Compress::Xz, IO::Uncompress::UnXz, IO::Compress::Lzip, IO::Uncompress::UnLzip,\nIO::Compress::Lzop, IO::Uncompress::UnLzop, IO::Compress::Lzf, IO::Uncompress::UnLzf,\nIO::Compress::Zstd, IO::Uncompress::UnZstd, IO::Uncompress::AnyInflate,\nIO::Uncompress::AnyUncompress\n\nIO::Compress::FAQ\n\nFile::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib\n\nFor RFC 1950, 1951 and 1952 see <http://www.faqs.org/rfcs/rfc1950.html>,\n<http://www.faqs.org/rfcs/rfc1951.html> and <http://www.faqs.org/rfcs/rfc1952.html>\n\nThe *zlib* compression library was written by Jean-loup Gailly \"gzip@prep.ai.mit.edu\" and Mark\nAdler \"madler@alumni.caltech.edu\".\n\nThe primary site for the *zlib* compression library is <http://www.zlib.org>.\n\nThe primary site for gzip is <http://www.gzip.org>.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "This module was written by Paul Marquess, \"pmqs@cpan.org\".\n",
                "subsections": []
            },
            "MODIFICATION HISTORY": {
                "content": "See the Changes file.\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "Copyright (c) 2005-2021 Paul Marquess. All rights reserved.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
                "subsections": []
            }
        }
    }
}