ZLib

Introduction and Overview

The ZLib module provides a shared interface to the ZLib compression library. It provides a simple SWI interface, and a direct library replacement interface. The simple SWI interface looks the same as that for Squash will act as such. The direct replacement interface provides a number of SWIs which may be accessed as is they were the original C routines.

To complement the SWI interface, a C library is also provided as a set of veneer functions to allow the ZLib library to be called as if it had been statically linked.

The 'zlib' compression library provides lossless in-memory compression and decompression functions, including integrity checks of the uncompressed data. Compression can be done in a single step if the buffers are large enough (for example if an input file is mmap'ed), or can be done by repeated calls of the compression function. In the latter case, the caller must provide more input and/or consume the output (providing more output space) before each call.

Terminology

ZLib (q.v. RFC 1950) is a standard, freely available library produced by Jean-loup Gailly and Mark Adler which provides compression based on the standard 'deflate' algorithm (q.v. RFC 1951). In addition, the ZLib library (and module) supports the GZip compression algorithm (q.v. RFC 1952) with extensions for RISC OS file information.

Technical Details

The ZLib module provides two primary interfaces for the programmer. The first of these is a Squash-like interface to the ZLib library. Applications which already support the use of Squash can be changed to use ZLib by simply changing the SWIs that are called.

The second interface that the module provides is that of a direct replacement for the ZLib C library. Because this is provided as a SWI interface, this means that it is accessible to applications written in any language.

ZLib SWI interface

This SWIs that the module provides have equivilent (or similar) names to those of the C interface. A C interface library is provided to interact with the ZLib module such that it should not be necessary to use these calls directly from C.

Informational SWIs

The informational calls are not related to providing compression. These SWIs are the CRC32, Adler32 and Version SWIs.

GZip SWIs

The GZip calls provide GZip file compression. GZip files are compressed containers for a single file of data. GZip files contain additional information about the file they contain. This additional information is used to store RISC OS-specific file data such as the filetype, and datestamp.

ZLib SWIs

The ZLib calls provide deflate format data compression. Data compressed by the deflate algorithm is extractable by equivilent deflate decompressors. No additional data is included within the compressed data about its source. If further meta-data is required, it should be included in the output format in some application specific format. Zip files are one such example of a deflate format encapsulation.

Data formats

Stream Control Block

In order to function, a 'stream control block' must be provided to the ZLib SWIs. This control block is a private structure which can be manipulated by both the client and the ZLib module. Initially, the table should be set to 0 before being called (except where indicated).

OffsetNameContents
0next_inPointer to the next available input byte. This value should be zero initially, and be updated by both the client and the ZLib module as data is processed.
4avail_inAmount of input data available for use by the ZLib module. This value should be zero initially, and be updated by both the client and the ZLib module as data is processed.
8total_outTotal number of bytes read so far.
12next_outPointer to the next output byte. This value should be zero initially, and be updated by both the client and the ZLib module as data is processed.
16avail_outAmount of space in the output buffer for use by the ZLib module. This value should be zero initially, and be updated by both the client and the ZLib module as data is processed.
20total_outTotal number of bytes output so far.
24msgPointer to the last error message, or 0 if no error has been generated.
28statePrivate value, controlled by the ZLib module. The client should not modify this value.
32zallocAddress of memory allocator function, or 0 for ZLib to control memory allocation.
36zfreeAddress of memory free function, or 0 for ZLib to control memory allocation.
40opaqueOpaque handle to pass to allocator and free functions.
44data_typeZLib module's guess of the type of the data :
ValueMeaning
0Binary
1ASCII
2Unknown
48adlerAdler-32 value for uncompressed data processed so far.
52reservedReserved for future expansion. Must be zero.

Flush types

Where data is being written to a stream, a 'flush type' is provided to describe what sort of operations should be performed on writing the data. Flushing may degrade compression for some compression algorithms and so it should be used only when necessary.

TypeNameMeaning
0Z_NO_FLUSH Do not flush data, but just write data as normal to the output buffer. This is the normal way in which data is written to the output buffer.
1Z_PARTIAL_FLUSH Obsolete. You should use Z_SYNC_FLUSH instead.
2Z_SYNC_FLUSH All pending output is flushed to the output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input data available so far.
3Z_FULL_FLUSH All output is flushed as with Z_SYNC_FLUSH, and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if random access is desired. Using Z_FULL_FLUSH too often can seriously degrade the compression. SWI ZLib_InflateSync will locate points in the compression string where a full has been performed.
4Z_FINISH Notifies the module that the input has now been exhausted. Pending input is processed, pending output is flushed and calls return with Z_STREAM_END if there was enough output space.

Compression levels

For compression calls, the compression level can be specified. This determines how much work is performed on trying to compress the input data. Lower compression levels indicate lesser compression, and greater speed. Higher levels indicate greater compression, but lesser speed.

LevelNameMeaning
0Z_NO_COMPRESSIONNo compression should be used at all.
1Z_BEST_SPEEDMinimal compression, but greatest speed.
9Z_BEST_COMPRESSIONMaximum compression, but slowest.
-1Z_DEFAULT_COMPRESSIONSelect default compression level.

Compression strategy

For compression calls, the compression strategy can be specified. This determines what type of processing is performed on the input data. If set incorrectly, the compression strategy will produce lesser compression ratios, but does not affect the correctness of the data.

StrategyNameMeaning
0Z_DEFAULT_STRATEGYThe default strategy is the most commonly used. With this strategy, string matching and huffman compression are balanced.
1Z_FILTEREDThis strategy is designed for filtered data. Data which consists of mostly small values, with random distribution should use Z_FILTERED. With this strategy, less string matching is performed.
2Z_HUFFMAN_ONLYThis strategy performs no string matching, only the huffman encoding is performed.

Compression method

The compression method determines what algorithm is used to perform the compression. Presently only Z_DEFLATED is supported.

MethodNameMeaning
8Z_DEFLATEDUse deflate algorithm

Memory level

The memory level determines how much memory should be allocated for the internal compression state. The default value is 8.

LevelMeaning
1Uses minimal memory, but is slow and reduces the compression ratio.
9Uses maximum memory for optimal speed.

Window bits

Whilst searching for matching strings in the input data, a 'window' is used on to the previous data. This window is used to determine where matches occur. The value of the 'window bits' parameter is the base two logarithm of the size of the window. It should be in the range 9 to 15 for this version of the library. Larger values result in better compression at the expense of memory usage.

ZLib return code

Most ZLib SWIs return a 'return code'. This declares the state that the SWI encountered during the operation.

CodeNameMeaning
0Z_OKNo failure was encountered, the operation completed without problem.
1Z_STREAM_ENDNo failure was encountered, and the input has been exhausted.
2Z_NEED_DICTA preset dictionary is required for the decompression of the data.
-1Z_ERRNOAn internal error occurred
-2Z_STREAM_ERRORThe stream structure was inconsistant
-3Z_DATA_ERRORInput data has been corrupted (for decompression).
-4Z_MEM_ERRORMemory allocation failed.
-5Z_BUF_ERRORThere was not enough space in the output buffer.
-6Z_VERSION_ERRORThe version supplied does not match that supported by the ZLib module.

SWI calls

ZLib_CompressSWI &53AC0
Simple Squash-like compression
R0=Flags :
Bit(s)Meaning
0Continue previously started operation
1More input remains after this call
2Reserved, must be 0
3Return workspace required
4Workspace is not bound to an application
5-10Reserved, must be 0
R1 - R5=dependant on flags
R0 - R5=dependant on flags
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is similar to SWI Squash_Compress, providing a drop in replacement for the Squash module but using ZLib compression. There are two variants of this SWI - with bit 3 set, and with bit 3 clear. Normally, this call will be made first with bit 3 set to read the workspace size, and then with bit 3 clear to perform the decompression.

ZLib_Compress bit 3 setRead workspaceSWI &53AC0
Simple Squash-like compression
R0=Flags :
Bit(s)Meaning
3Return workspace required
R1=input size, or -1 to omit maximum output size
R0=required workspace size
R1=maximum output size, or -1 if it cannot be determined or was not asked for
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to read the size of the buffers to use for ZLib compression via the Squash-like interface.

ZLib_Compress bit 3 clearCompressSWI &53AC0
Simple Squash-like compression
R0=Flags :
Bit(s)Meaning
0Continue previously started operation
1More input remains after this call
3Return workspace required
4Workspace is not bound to an application
R1=pointer to workspace
R2=pointer to input data
R3=length of input data
R4=pointer to output buffer
R5=length of output buffer
R0=status of decompression process :
ValueMeaning
0Operation is complete
1Input has been exhausted
2Output space has been exhausted
R1preserved
R2=pointer to first unused byte of input data
R3=size of unused data in input buffer
R4=pointer to first unused byte of output buffer
R5=size of unused data in output buffer
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to compress data to a buffer.

ZLib_DecompressSWI &53AC1
Simple Squash-like decompression
R0=Flags :
Bit(s)Meaning
0Continue previously started operation
1More input remains after this call
2Assume all output will fit into the buffer
3Return workspace required
4Workspace is not bound to an application
5-10Reserved, must be 0
R1 - R5=dependant on flags
R0 - R5=dependant on flags
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is similar to SWI Squash_Compress, providing a drop in replacement for the Squash module but using ZLib decompression. There are two variants of this SWI - with bit 3 set, and with bit 3 clear. Normally, this call will be made first with bit 3 set to read the workspace size, and then with bit 3 clear to perform the decompression.

ZLib_Decompress bit 3 setRead workspaceSWI &53AC1
Simple Squash-like decompression
R0=Flags :
Bit(s)Meaning
3Return workspace required
R1=input size, or -1 to omit maximum output size
R0=required workspace size
R1=maximum output size, or -1 if it cannot be determined or was not asked for
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to read the size of the buffers to use for ZLib decompression via the Squash-like interface.

ZLib_Decompress bit 3 clearDecompressSWI &53AC1
Simple Squash-like decompression
R0=Flags :
Bit(s)Meaning
0Continue previously started operation
1More input remains after this call
3Return workspace required
4Workspace is not bound to an application
R1=pointer to workspace
R2=pointer to input data
R3=length of input data
R4=pointer to output buffer
R5=length of output buffer
R0=status of decompression process :
ValueMeaning
0Operation is complete
1Input has been exhausted
2Output space has been exhausted
R1preserved
R2=pointer to first unused byte of input data
R3=size of unused data in input buffer
R4=pointer to first unused byte of output buffer
R5=size of unused data in output buffer
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to decompress data from a buffer.

ZLib_CRC32SWI &53AC2
Calculate a CRC32 checksum for a given data buffer (crc32)
R0=CRC-32 continuation value
R1=pointer to start of block, or 0 to read the initial value to supply as a continuation value.
R2=pointer to end of block
R0=CRC-32 value for block
R1 - R2preserved
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to update a running CRC-32 checksum with data from a buffer. The returned CRC-32 value should be passed back to the this SWI if the checksum needs updating further. ZLib_CRC32 is a slower call than OS_CRC, but more reliable.

ZLib_Adler32SWI &53AC3
Calculate an Adler32 checksum for a given data buffer (adler32)
R0=Adler-32 continuation value
R1=pointer to start of block, or 0 to read the initial value to supply as a continuation value.
R2=pointer to end of block
R0=Adler-32 value for block
R1 - R2preserved
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to update a running Adler-32 checksum with data from a buffer. The returned Adler-32 value should be passed back to the this SWI if the checksum needs updating further. Adler-32 is a faster checksum to calculate than CRC-32.

ZLib_VersionSWI &53AC4
Return the version of ZLib in use (zlib_version)
None
R0=pointer to read only version string
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to read the version number of the ZLib library in use.

ZLib_ZCompressSWI &53AC5
Compress a source buffer (compress)
R0=pointer to output buffer for compressed data
R1=length of output buffer
R2=pointer to input buffer of uncompressed data
R3=length of input buffer
R0=ZLib return code
R1=length of output buffer used
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to compress a block of data in a single call. The output buffer must be at least 0.1% larger than the input, plus 12 bytes.

ZLib_ZCompress2SWI &53AC6
Compress a source buffer (compress2)
R0=pointer to output buffer for compressed data
R1=length of output buffer
R2=pointer to input buffer of uncompressed data
R3=length of input buffer
R4=compression level
R0=ZLib return code
R1=length of output buffer used
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is equivilent to ZLib_Compress, but allows the compression level to be specified.

ZLib_ZUncompressSWI &53AC7
Compress a source buffer (uncompress)
R0=pointer to output buffer for uncompressed data
R1=length of output buffer
R2=pointer to input buffer of compressed data
R3=length of input buffer
R0=ZLib return code
R1=length of output buffer used
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI decompresses a buffer of data in a single call. The destination buffer must be large enough for the decompressed data.

ZLib_DeflateInitSWI &53AC8
Initialise a stream for compression (deflateInit)
R0=pointer to #subsubsection_stream_control_block
R1=compression level
R2=pointer to ZLib version string expected ("1.1.4" at time of writing)
R3=length of control block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to initialise the ZLib compression algorithm. You should clear the workspace block to zeros. zalloc and zfree may point to routines to allocate and free memory. If these are not set then memory is allocated on a per application basis in the global dynamic area. zalloc and zfree will be entered within a C environment (ie APCS applies) with a small stack, in SVC mode. Because of this, you cannot use longjmp, use functions that require large amounts of stack space, or perform any non-SVC mode operation. Contact RISCOS Ltd if you wish to use this feature but are unsure how it will affect your code.

ZLib_InflateInitSWI &53AC9
Initialise a stream for decompression (inflateInit)
R0=pointer to #subsubsection_stream_control_block
R1=pointer to ZLib version string expected ("1.1.4" at time of writing)
R2=length of control block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to initialise the ZLib stream decompression algorithm. You should clear the workspace block to zeros. zalloc and zfree may point to routines to allocate and free memory. If these are not set then memory is allocated on a per application basis in the global dynamic area. zalloc and zfree will be entered within a C environment (ie APCS applies) with a small stack, in SVC mode. Because of this, you cannot use longjmp, use functions that require large amounts of stack space, or perform any non-SVC mode operation. Contact RISCOS Ltd if you wish to use this feature but are unsure how it will affect your code.

ZLib_DeflateInit2SWI &53ACA
Initialise a stream for compression with control over parameters (deflateInit2)
R0=pointer to #subsubsection_stream_control_block
R1=compression level
R2=compression method
R3=window bits for history buffer
R4=memory level
R5=compression strategy
R6=pointer to ZLib version string expected ("1.1.4" at time of writing)
R7=length of control block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is similar to ZLib_DeflateInit, but provides much greater control than that SWI.

ZLib_InflateInit2SWI &53ACB
Initialise a stream for decompression with control over parameters (inflateInit2)
R0=pointer to #subsubsection_stream_control_block
R1=window bits
R2=pointer to ZLib version string expected ("1.1.4" at time of writing)
R3=length of control block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is similar to ZLib_InflateInit, but provides much greater control than that SWI.

ZLib_DeflateSWI &53ACC
Continue a stream compression (deflate)
R0=pointer to #subsubsection_stream_control_block
R1=flush type
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. next_in and avail_in are read and updated after data has been processed. You should empty the output buffer when data appears there (next_out and avail_out will have been updated).

ZLib_Deflate performs one or both of the following actions:

  • Compress more input starting at next_in and update next_in and avail_in accordingly. If not all input can be processed (because there is not enough room in the output buffer), next_in and avail_in are updated and processing will resume at this point for the next call of ZLib_Deflate.
  • Provide more output starting at next_out and update next_out and avail_out accordingly. This action is forced if the parameter flush is non zero. Forcing flush frequently degrades the compression ratio, so this parameter should be set only when necessary (in interactive applications). Some output may be provided even if flush is not set.

Before calling ZLib_Deflate, the client should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating avail_in or avail_out accordingly; avail_out should never be zero before the call. The client may consume the compressed output when it wants, for example when the output buffer is full (avail_out == 0), or after each call of ZLib_Deflate. If deflate returns Z_OK and with zero avail_out, it must be called again after making room in the output buffer because there might be more output pending.

If the flush type is set to Z_SYNC_FLUSH, all pending output is flushed to the output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input data available so far. In particular avail_in is zero after the call if enough output space has been provided before the call. Flushing may degrade compression for some compression algorithms and so it should be used only when necessary.

If the flush type is set to Z_FULL_FLUSH, all output is flushed as with Z_SYNC_FLUSH, and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if random access is desired. Using Z_FULL_FLUSH too often can seriously degrade the compression.

If deflate returns with avail_out == 0, this function must be called again with the same value of the flush parameter and more output space (updated avail_out), until the flush is complete (ZLib_Deflate returns with non-zero avail_out).

If the flush type is set to Z_FINISH, pending input is processed, pending output is flushed and ZLib_Deflate returns with Z_STREAM_END if there was enough output space; if ZLib_Deflate returns with Z_OK, this function must be called again with Z_FINISH and more output space (updated avail_out) but no more input data, until it returns with Z_STREAM_END or an error. After ZLib_Deflate has returned Z_STREAM_END, the only possible operations on the stream are SWI ZLib_DeflateReset or SWI ZLib_DeflateEnd.

Z_FINISH can be used immediately after SWI ZLib_DeflateInit if all the compression is to be done in a single step. In this case, avail_out must be at least 0.1% larger than avail_in plus 12 bytes. If ZLib_Deflate does not return Z_STREAM_END, then it must be called again as described above.

ZLib_Deflate sets adler to the adler32 checksum of all input read so far (that is, total_in bytes).

ZLib_Deflate may update data_type if it can make a good guess about the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered binary. This field is only for information purposes and does not affect the compression algorithm in any manner.

ZLib_Deflate returns Z_OK if some progress has been made (more input processed or more output produced), Z_STREAM_END if all input has been consumed and all output has been produced (only when the flush type is set to Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible (for example avail_in or avail_out was zero).

ZLib_DeflateEndSWI &53ACD
Terminate a stream compression (deflateEnd)
R0=pointer to #subsubsection_stream_control_block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI frees all the memory used by the compression algorithm, discarding any unprocessed input or output.

ZLib_InflateSWI &53ACE
Continue decompressing a stream (inflate)
R0=pointer to #subsubsection_stream_control_block
R1=flush type
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. next_in and avail_in are read and updated after data has been processed. You should empty the output buffer when data appears there (next_out and avail_out will have been updated).

ZLib_Inflate performs one or both of the following actions:

  • Decompress more input starting at next_in and update next_in and avail_in accordingly. If not all input can be processed (because there is not enough room in the output buffer), next_in is updated and processing will resume at this point for the next call of ZLib_Inflate.
  • Provide more output starting at next_out and update next_out and avail_out accordingly. ZLib_Inflate provides as much output as possible, until there is no more input data or no more space in the output buffer (see below about the flush parameter).

Before the call of ZLib_Inflate, the application should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating the next_in/next_out and avail_in/avail_out values accordingly. The application can consume the uncompressed output when it wants, for example when the output buffer is full (avail_out == 0), or after each call of ZLib_Inflate. If this SWI returns Z_OK and with zero avail_out, it must be called again after making room in the output buffer because there might be more output pending.

If R1 is set to Z_SYNC_FLUSH, ZLib_Inflate flushes as much output as possible to the output buffer. The flushing behavior of inflate is not specified for values of the flush parameter other than Z_SYNC_FLUSH and Z_FINISH, but the current implementation actually flushes as much output as possible anyway.

ZLib_Inflate should normally be called until it returns Z_STREAM_END or an error. However if all decompression is to be performed in a single step (a single call of ZLib_Inflate), the parameter flush should be set to Z_FINISH. In this case all pending input is processed and all pending output is flushed ; avail_out must be large enough to hold all the uncompressed data. (The size of the uncompressed data may have been saved by the compressor for this purpose.) The next operation on this stream must be inflateEnd to deallocate the decompression state. The use of Z_FINISH is never required, but can be used to inform inflate that a faster routine may be used for the single ZLib_Inflate call.

If a preset dictionary is needed at this point (see #swi_zlib_inflatesetdictionary below), ZLib_Inflate sets adler to the Adler-32 checksum of the dictionary chosen by the compressor and returns Z_NEED_DICT ; otherwise it sets adler to the Adler-32 checksum of all output produced so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described below. At the end of the stream, ZLib_Inflate checks that its computed Adler-32 checksum is equal to that saved by the compressor and returns Z_STREAM_END only if the checksum is correct.

ZLib_Inflate returns Z_OK if some progress has been made (more input processed or more output produced), Z_STREAM_END if the end of the compressed data has been reached and all uncompressed output has been produced, Z_NEED_DICT if a preset dictionary is needed at this point, Z_DATA_ERROR if the input data was corrupted (input stream not conforming to the ZLib format or incorrect Adler-32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no progress is possible or if there was not enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then call SWI ZLib_InflateSync to look for a good compression block.

ZLib_InflateEndSWI &53ACF
Terminate a decompression stream (inflateEnd)
R0=pointer to #subsubsection_stream_control_block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI frees all the memory used by the decompression algorithm, discarding any unprocessed input or output.

ZLib_DeflateSetDictionarySWI &53AD0
Initialise a string dictionary for a stream compression (deflateSetDictionary)
R0=pointer to #subsubsection_stream_control_block
R1=pointer to dictionary block (a stream of bytes)
R2=length of dictionary block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to initialise a compression dictionary. The dictionary consists of strings (byte sequences) that are likely to be encountered later in the data to be compressed, with the most commonly used strings preferably put towards the end of the dictionary.

The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be compressed, with the most commonly used strings preferably put towards the end of the dictionary. Using a dictionary is most useful when the data to be compressed is short and can be predicted with good accuracy ; the data can then be compressed better than with the default empty dictionary.

Depending on the size of the compression data structures selected by ZLib_DeflateInit or ZLib_DeflateInit2, a part of the dictionary may in effect be discarded, for example if the dictionary is larger than the window size in ZLib_Deflate or ZLib_Deflate2. Thus the strings most likely to be useful should be put at the end of the dictionary, not at the front.

Upon return of this function, adler is set to the Adler-32 value of the dictionary; the decompressor may later use this value to determine which dictionary has been used by the compressor. (The Adler32 value applies to the whole dictionary even if only a subset of the dictionary is actually used by the compressor.)

ZLib_DeflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a parameter is invalid (such as NULL dictionary) or the stream state is inconsistent (for example if ZLib_Deflate has already been called for this stream). ZLib_DeflateSetDictionary does not perform any compression: this will be done by ZLib_Deflate.

ZLib_DeflateCopySWI &53AD1
Copy the compression state (deflateCopy)
R0=pointer to destination #subsubsection_stream_control_block
R1=pointer to source #subsubsection_stream_control_block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to take a copy of the current compression state. This might be useful if you are attempting to filter the data in one of a number of ways.

ZLib_DeflateResetSWI &53AD2
Reset the internal compression state (deflateReset)
R0=pointer to #subsubsection_stream_control_block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is equivilent to ZLib_DeflateEnd followed by ZLib_DeflateInit.

ZLib_DeflateParamsSWI &53AD3
Modifies the compression parameters (deflateParams)
R0=pointer to #subsubsection_stream_control_block
R1=compression level
R2=compression strategy
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is updates the compression level and strategy. You may do this part way through compression.

ZLib_InflateSetDictionarySWI &53AD4
Initialise a string dictionary for a decompression stream (inflateSetDictionary)
R0=pointer to #subsubsection_stream_control_block
R1=pointer to dictionary block (a stream of bytes)
R2=length of dictionary block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to initialise a decompression dictionary. The dictionary must be the same as that used to compress the data (ZLib_DeflateSetDictionary).

ZLib_InflateSyncSWI &53AD5
Re-synchronise decompression stream (inflateSetDictionary)
R0=pointer to #subsubsection_stream_control_block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI will skip invalid data until a full flush point is found. This may be useful if you have data which is likely to be corrupted, is periodically synchronised and the data 'lost' is unimportant. An example might be a stream of graphical or audio data.

ZLib_InflateResetSWI &53AD6
Reset the decompression stream state (inflateReset)
R0=pointer to #subsubsection_stream_control_block
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is equivilent to ZLib_InflateEnd followed by ZLib_InflateInit.

ZLib_GZOpenSWI &53AD7
Open a GZip file for reading or writing (gzopen)
R0=pointer to filename
R1=pointer to the 'mode' of file operation. This consists of two parts; the access type and the modifiers. Only one access type may be used, but multiple modifiers may be added to the end.
Access typeMeaning
rbOpen for reading
wbOpen for writing
ModifierMeaning
0-9compression level
hHuffman compression only
fData is 'filtered' (small values, randomly distributed)
fRISC OS type information attached
R2=load address of file (if 'R' and 'wb' used)
R3=exec address of file (if 'R' and 'wb' used)
R4=length address of file (if 'R' and 'wb' used)
R5=attributes address of file (if 'R' and 'wb' used)
R0=opaque GZip handle
R2=load address of file (if 'R' and 'rb' used)
R3=exec address of file (if 'R' and 'rb' used)
R4=length address of file (if 'R' and 'rb' used)
R5=attributes address of file (if 'R' and 'rb' used)
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI opens a file for accessing GZip compressed data. The 'R' extension is intended for compressing RISC OS files completely losslessly. Expanding such files on other systems will result in the loss of RISC OS type information only; the file data itself will be intact.

ZLib_GZReadSWI &53AD8
Read data from a GZip file (gzread)
R0=opaque GZip handle
R1=pointer to destination buffer
R2=amount of data to read
R0=number of bytes read
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI reads data from a previously opened GZip file.

ZLib_GZWriteSWI &53AD9
Write data to a GZip file (gzwrite)
R0=opaque GZip handle
R1=pointer to source buffer
R2=amount of data to write
R0=number of bytes written
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI writes data to a previously opened GZip file.

ZLib_GZFlushSWI &53ADA
Flush all pending data to a GZip file (gzflush)
R0=opaque GZip handle
R1=flush type
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI writes data to a previously opened GZip file.

ZLib_GZCloseSWI &53ADB
Close a GZip file (gzclose)
R0=opaque GZip handle
R0=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI closes a previously opened GZip file.

ZLib_GZErrorSWI &53ADC
Close a GZip file (gzclose)
R0=opaque GZip handle
R0=pointer to last error message string
R1=ZLib return code
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI returns the last error message returned by a GZip operation.

ZLib_GZSeekSWI &53ADD
Move to a specific location in a GZip file (gzseek)
R0=opaque GZip handle
R1=position in decompressed data in bytes
R2=type of seek to perform :
TypeMeaning
0Set absolute position (position = R1)
1Set relative position (position = R1 + current position)
R0=new position in file
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI changes the pointer within a GZip file. The position specified is located such that byte number R1 had just been read from the file. The operation cannot be performed on files being written.

ZLib_GZTellSWI &53ADE
Return the current position in a GZip file (gztell)
R0=opaque GZip handle
R0=current position in decompressed data in bytes
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI returns the current position in the decompressed data in bytes as an offset from the start of the data.

ZLib_GZEOFSWI &53ADF
Check whether the end of file has been reached (gztell)
R0=opaque GZip handle
R0=1 if EOF condition has been reached, 0 otherwise
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI checks whether the end of the file has been reached.

ZLib_TaskAssociateSWI &53AE0
Change Wimp Task association for a stream
R0=pointer to #subsubsection_stream_control_block
R0preserved
Interrupts are disabled
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

This SWI is used to associate a ZLib stream with a task. When associated, the tasks death will cause the memory allocated to the stream to be released automatically. If dissociated, the stream will never be freed unless the deflateEnd or inflateEnd calls are issued.

By default all streams are associated with the task with which they were created and destroyed automatically should that task terminate. You may wish to disable this operation using this SWI.