nlib
nn::nlib::ZlibOutputStream Class Referencefinal

The class that uses zlib to decompress data and write the data to a stream. More...

#include "nn/nlib/ZlibOutputStream.h"

+ Inheritance diagram for nn::nlib::ZlibOutputStream:

Public Member Functions

errno_t Init () noexcept
 Initializes using the default settings. More...
 
errno_t Init (const ZlibOutputStreamSettings &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
 ZlibOutputStream () noexcept
 Instantiates the object with default parameters (default constructor).
 
- Public Member Functions inherited from nn::nlib::OutputConverterStream
errno_t SetStream (OutputStream *ostr) noexcept
 Sets an output stream as the base stream. More...
 
OutputStreamGetStream () const noexcept
 Gets the input stream that will be the base stream. More...
 
- Public Member Functions inherited from nn::nlib::OutputStream
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 integer. More...
 
bool Write (int b) noexcept
 Writes one byte of data to the stream. More...
 
bool Write (const void *p, size_t n) noexcept
 Writes n bytes of data to the stream. More...
 
bool WriteGather (const nlib_fd_iovec *iov, int iovcnt) noexcept
 Writes data from multiple non-continuous buffers to a stream. More...
 
bool Flush () noexcept
 Flushes the stream. More...
 
bool Close () noexcept
 Closes the stream after it has been flushed. Returns true if successful. More...
 
errno_t GetErrorValue () const noexcept
 Gets the error value. More...
 
BufferingMode GetBufferingMode () const noexcept
 Gets the buffering mode.
 
 operator bool () const
 Returns true if no internal error has occurred.
 
constexpr OutputStream () noexcept
 Instantiates the object with default parameters (default constructor).
 
virtual ~OutputStream () noexcept
 Destructor. Does not do anything.
 

Additional Inherited Members

- Public Types inherited from nn::nlib::OutputStream
enum  BufferingMode {
  kBufferingModeBlockBuffered = 0,
  kBufferingModeLineBuffered,
  kBufferingModeUnbuffered
}
 The buffering mode for OutputStream. More...
 
- Protected Member Functions inherited from nn::nlib::OutputStream
void ResetBuffer (void *p, size_t nbytes) noexcept
 Sets the buffer held by OutputStream. More...
 
void SetError (errno_t e) const noexcept
 Sets an error to OutputStream. More...
 
- Protected Attributes inherited from nn::nlib::OutputStream
BufferingMode m_BufferingMode
 Stores the buffering mode. More...
 

Detailed Description

The class that uses zlib to decompress data and write the data to a stream.

Description
The data written to a stream is compressed by zlib. Even large amounts of data can be streamed and written.
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 writing the data in the same way as OutputStream. When you close this stream, the base stream is flushed and detached, reverting to the state before SetStream was called. The base stream itself is not closed.
The following errors can occur during the writing of data. errno error values are set for zlib errors.
  • If Z_STREAM_ERROR -> EIO.
  • If Z_MEM_ERROR -> ENOMEM.
  • If Z_BUF_ERROR -> ENOBUFS.
  • If base stream fails -> EIO.
The transition of the object state.
The overview of the object state transitions is described below:
dot_inline_dotgraph_14.png
Examples:
misc/usezlib/usezlib.cpp.

Definition at line 57 of file ZlibOutputStream.h.

Member Function Documentation

◆ Init() [1/2]

nn::nlib::ZlibOutputStream::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.
ZlibOutputStreamSettings settings;
The deflateInit2 function is called inside the SetStream function to initialize for data compression.
Currently, the windowBits parameter is set to 31, memLevel is set to 8, and strategy is set to Z_DEFAULT_STRATEGY. zalloc, zfree, and opaque for z_stream are all set to Z_NULL.
The error values are as follows:
  • If the base stream is already set, the function returns EEXIST.
  • If ostr is NULL, the function returns EINVAL.
The errors returned by the deflateInit2 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.

Definition at line 61 of file ZlibOutputStream.h.

◆ Init() [2/2]

nn::nlib::ZlibOutputStream::Init ( const ZlibOutputStreamSettings 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: