SWI-Prolog binding to zlib
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog binding to zlib
        • Zlib and compression
        • Predicate reference
          • zopen/3
          • gzopen/3
          • gzopen/4
        • Interaction with Prolog stream predicates

2 Predicate reference

zopen(+Stream, -ZStream, +Options)
Creates ZStream, providing compressed access to Stream. If an input stream is wrapped, it recognises a gzip or deflate header. If an output stream is wrapped, Options define the desired wrapper and compression level. The new ZStream inherits its encoding from Stream. In other words, if Stream is a text-stream, so is ZStream. The original Stream is switched to binary mode while it is wrapped. The original encoding of Stream is restored if ZStream is closed. Note that zopen/3 does not actually process any data and therefore succeeds on input streams that do not contain valid data. Errors may be generated by read operations performed on the stream.

Defined options on output streams are:

format(+Format)
Either deflate (default), raw_deflate or gzip. The deflate envelope is simple and short and is typically used for compressed (network) communication. The raw_deflate does not include an envelope and is often used as a step in crypographic encodings. The gzip envelope is compatible to the gzip program and intended to read/write compressed files.
level(+Level)
Number between 0 and 9, specifying the compression level, Higher levels use more resources. Default is 6, generally believed to be a good compromise between speed, memory requirement and compression.
multi_part(+Boolean)
If true, restart reading if the input is not at end-of-file. The default is true for gzip streams.

Generic options are:

close_parent(Bool)
If true (default), closing the compressed stream also closes (and thus invalidates) the wrapped stream. If false, the wrapped stream is not closed. This can be used to read/write a compressed data block as partial input/output on a stream.
gzopen(+File, +Mode, -Stream)
Same as gzopen(File, Mode, Stream,[]).
gzopen(+File, +Mode, -Stream, +Options)
Open gzip compatible File for reading or writing. If a file is opened in =append= mode, a new gzip image will be added to the end of the file. The gzip standard defines that a file can hold multiple gzip images and inflating the file results in a concatenated stream of all inflated images. Options are passed to open/4 and zopen/3. Default format is gzip.