nlib
nn::nlib::ZlibInputStream Class Referencefinal

The stream class for reading compressed data using zlib. More...

#include "nn/nlib/ZlibInputStream.h"

+ Inheritance diagram for nn::nlib::ZlibInputStream:

Public Member Functions

errno_t Init () noexcept
 Initializes using the default settings. More...
 
errno_t Init (const ZlibInputStreamSettings &settings) noexcept
 Configures the buffer and the other settings to use for streaming according to the values specified in the settings parameter. More...
 
Basic Member Functions
constexpr ZlibInputStream () noexcept
 Instantiates the object with default parameters (default constructor).
 
- Public Member Functions inherited from nn::nlib::InputConverterStream
errno_t SetStream (InputStream *istr) noexcept
 Sets the input stream for reading the pre-converted data. More...
 
InputStreamGetStream () const noexcept
 Gets the input stream for reading the pre-converted data. More...
 
- Public Member Functions inherited from nn::nlib::InputStream
errno_t GetErrorValue () const noexcept
 Gets the error value. More...
 
size_t Pos () const noexcept
 Returns the current position in the stream. More...
 
uint64_t Pos64 () const noexcept
 Returns the current position in the stream as a 64-bit value. More...
 
bool IsEos () noexcept
 Returns true if the stream is finished being read through to the end. If the stream has not been read through to the end, or if an error occurs, the function returns false. More...
 
int Read () noexcept
 Reads one byte of data from the stream. More...
 
int Peek () noexcept
 Reads the next byte without consuming the stream. More...
 
size_t Skip (size_t nbytes) noexcept
 Skips over the number of bytes specified by nbytes. More...
 
size_t Read (void *ptr, size_t nbytes) noexcept
 Reads the number of bytes of data specified by nbytes into the memory region specified by ptr. More...
 
bool Close () noexcept
 Closes the stream. Returns true if successful. More...
 
 operator bool () const
 Returns true if no internal error has occurred.
 
constexpr InputStream () noexcept
 Instantiates the object. This function is called from the derived class.
 
virtual ~InputStream () noexcept
 Destructor. This function is called from the derived class.
 

Additional Inherited Members

- Protected Member Functions inherited from nn::nlib::InputStream
void ResetBuffer (void *p, size_t nbytes) noexcept
 Sets the buffer held by InputStream. More...
 
void SetError (errno_t e) const noexcept
 Sets an error to InputStream. More...
 

Detailed Description

The stream class for reading compressed data using zlib.

Description
Reads streaming data that has been uncompressed using zlib. Even large amounts of data can be streamed and read.
The method involves constructing the object, using the Init function to configure the buffer and the like, using the SetStream function to associate the base stream, and then reading the data in the same way as InputStream.
When you close this stream, the base stream is detached, reverting to the state before SetStream was called. The base stream itself is not closed.
The following errors can occur during the reading of data. errno error values are set for zlib errors.
  • If Z_DATA_ERROR -> EILSEQ.
  • If Z_NEED_DICT -> EILSEQ.
  • If Z_STREAM_ERROR -> EIO.
  • If Z_MEM_ERROR -> ENOMEM.
  • If Z_BUF_ERROR -> ENOBUFS.
  • If unexpected EOF found -> EOF.
  • If base stream fails -> EIO.
The following is a description of the behavior of the SetStream function.
The function calls inflateInit2 to initialize for the extraction of data. The windowBits parameter of inflateInit2 is currently set to 47. zalloc, zfree, and opaque for z_stream are all set to Z_NULL.
The errors returned by the inflateInit2 function of zlib are converted as follows.
  • Z_MEM_ERROR is converted to ENOMEM.
  • Z_STREAM_ERROR is converted to EINVAL.
  • Z_VERSION_ERROR is converted to ENOTSUP.
The transition of the object state.
The overview of the object state transitions is described below:
dot_inline_dotgraph_13.png
Examples:
misc/usezlib/usezlib.cpp.

Definition at line 53 of file ZlibInputStream.h.

Member Function Documentation

◆ Init() [1/2]

nn::nlib::ZlibInputStream::Init ( )
inlinenoexcept

Initializes using the default settings.

Returns
Any value returned other than 0 indicates an error.
Description
This is the same as the following code.
ZlibInputStreamSettings settings;

Definition at line 58 of file ZlibInputStream.h.

◆ Init() [2/2]

nn::nlib::ZlibInputStream::Init ( const ZlibInputStreamSettings settings)
noexcept

Configures the buffer and the other settings to use for streaming according to the values specified in the settings parameter.

Parameters
[in]settingsThe settings data for the buffer and other settings.
Return values
0No error occurred.
EALREADYThe Init function is already running.
EINVALThe buffer size is smaller than 1024, or only one of the buffers specified in the settings parameter is NULL.
ENOMEMDynamic allocation of a buffer has failed.

The documentation for this class was generated from the following files: