.. _spicy_zlib_init:

.. rubric:: ``function spicy::zlib_init(window_bits: int64) : ZlibStream``

Initializes a zlib stream for decompression.

``window_bits``: Same as the corresponding parameter for zlib's `inflateInit2`
(see https://www.zlib.net/manual.html).

Will throw a `ZlibError` exception if initialization fails.

.. _spicy_zlib_decompress:

.. rubric:: ``function spicy::zlib_decompress(inout stream_: ZlibStream, data: bytes) : bytes``

Decompresses a chunk of data through the given zlib stream.

.. _spicy_zlib_finish:

.. rubric:: ``function spicy::zlib_finish(inout stream_: ZlibStream) : bytes``

Finalizes a zlib stream used for decompression.

.. _spicy_base64_encode:

.. rubric:: ``function spicy::base64_encode(inout stream_: Base64Stream, data: bytes) : bytes``

Encodes a stream of data into base64.

.. _spicy_base64_decode:

.. rubric:: ``function spicy::base64_decode(inout stream_: Base64Stream, data: bytes) : bytes``

Decodes a stream of base64 data back into the clear.

.. _spicy_base64_finish:

.. rubric:: ``function spicy::base64_finish(inout stream_: Base64Stream) : bytes``

Finalizes a base64 stream used for decoding or encoding.

.. _spicy_crc32_init:

.. rubric:: ``function spicy::crc32_init() : uint64``

Returns the initialization value for CRC32 computation.

.. _spicy_crc32_add:

.. rubric:: ``function spicy::crc32_add(crc: uint64, data: bytes) : uint64``

Computes a running CRC32.

.. _spicy_current_time:

.. rubric:: ``function spicy::current_time() : time``

Returns the current wall clock time.

.. _spicy_mktime:

.. rubric:: ``function spicy::mktime(y: uint64, m: uint64, d: uint64, H: uint64, M: uint64, S: uint64) : time``

Constructs a time value from a tuple of broken-out elements specifying local time.

- *y*: year (1970-...)
- *m*: month (1-12)
- *d*: day (1-31)
- *H*: hour (0-23)
- *M*: minute (0-59)
- *S*: second (0-59)

.. _spicy_bytes_to_hexstring:

.. rubric:: ``function spicy::bytes_to_hexstring(value: bytes) : string``

Returns a bytes value rendered as a hex string.

.. _spicy_getenv:

.. rubric:: ``function spicy::getenv(name: string) : optional<string>``

Returns the value of an environment variable, if set.

.. _spicy_strftime:

.. rubric:: ``function spicy::strftime(format: string, timestamp: time) : string``

Formats a time according to user-specified format string.

This function uses the currently active locale and timezone to format
values. Formatted strings cannot exceed 128 bytes.

The format string can contain format specifiers supported by POSIX strftime, see
https://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html.

This function can raise ``InvalidArgument`` if the timestamp could not be
converted to local time or formatted.

.. _spicy_strptime:

.. rubric:: ``function spicy::strptime(buf: string, format: string) : time``

Parses time from a string.

This function uses the currently active locale and timezone to parse values.

The format string can contain format specifiers supported by POSIX strptime, see
https://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html.

This function raises ``InvalidArgument`` if the string could not be parsed
with the given format string, or ``OutOfRange`` if the parsed time value cannot
be represented.

.. _spicy_parse_address:

.. rubric:: ``function spicy::parse_address(s: string) : addr``

Parses an address from a string. The address can be in standard IPv4 or IPv6
ASCII represententation. The function raises ``InvalidArgument`` if the string
could not be parsed.

.. _spicy_parse_address_2:

.. rubric:: ``function spicy::parse_address(b: bytes) : addr``

Parses an address from a bytes instance. The address can be in standard IPv4
or IPv6 ASCII represententation. The function raises ``InvalidArgument`` if the
string could not be parsed.

.. _spicy_accept_input:

.. rubric:: ``function spicy::accept_input()``

Reports a confirmation to the host application indicating that the parser
appears to be processing the expected input format. It's up to the host
application how to use this information.

.. _spicy_decline_input:

.. rubric:: ``function spicy::decline_input(reason: string)``

Reports a violation to the host application indicating that the parser
appears not to be processing the expected input format.  It's up to the
host application how to use this information.

Note that this does not automatically abort processing. If that's desired,
you need to trigger a parse error as well, e.g., by throwing an error,
`throw "<error message>"`.

reason: user-presentable description of why the input seems wrong

