Files
bluelib/compress/cstream.h
Max Wash ede5e72fc2 compress: cstream: add support for temporarily moving the cursor and performing limited i/o operations
the cursor can only be moved during uncompressed i/o, and any read/write operations are performed directly on the underlying endpoint with no buffering, and don't count towards the transacted byte statistics.

the cursor can only be moved once, after which it's position must be restored.
2025-07-31 11:18:10 +01:00

70 lines
2.3 KiB
C

#ifndef _CSTREAM_H_
#define _CSTREAM_H_
#include <blue/compress/function.h>
#include <blue/core/ringbuffer.h>
#include <stddef.h>
struct b_stream;
struct b_compressor;
enum cstream_flags {
CSTREAM_CURSOR_MOVED = 0x01u,
};
struct b_cstream {
enum cstream_flags s_flags;
struct b_stream *s_endpoint;
struct b_compressor *s_compressor;
/* s_in is the input buffer, and s_out is the output buffer.
*
* the input buffer holds data that will be provided to the
* (de)compression function. in compression mode, this data is provided
* by the code using the cstream (via b_cstream_write) in decompression
* mode, this data is read from s_endpoint.
*
* the output buffer holds data produced by the (de)compression
* function. in compression mode, this data will be written to
* s_endpoint. in decompression mode, this data will be returned to the
* code using the cstream (via b_cstream_read)
*
* heavy usage of cstream's compressed sections facility can result
* in the input buffer holding uncompressed data while the stream is in
* decompression mode. this is handled by the uncompressed read code path.
*/
struct b_ringbuffer s_in, s_out;
enum b_compression_mode s_mode;
unsigned int s_compression_depth;
/* tracks the number of compressed bytes that have passed through this
* stream in the current section.
*
* in compression mode, this tracks the number of post-compression bytes
* that have been written to the endpoint within the current section,
* including any bytes written during end_compression_section()
*
* in decompression mode, this tracks the number of compressed bytes
* that were decompressed while reading the current section. it does not
* include any uncompressed bytes that may have been read from the
* endpoint while reading a compressed section due to cstream's
* read-ahead caching behaviour.
*/
size_t s_tx_compressed_bytes;
/* tracks the number of uncompressed bytes that have passed through this
* stream in the current section.
*
* in compression mode, this tracks the number of bytes given to
* b_cstream_write
*
* in decompression mode, this tracks the number of bytes returned by
* b_cstream_read
*/
size_t s_tx_uncompressed_bytes;
/* when the endpoint cursor is moved, the previous cursor position is
* saved here so it can be restored later */
size_t s_cursor;
};
#endif