From c9f5cfd3df2706da940a39d6d816ad084ba80fbd Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 14 Sep 2020 14:59:31 +0200 Subject: Implement istream decompression support Signed-off-by: David Oberhollenzer --- include/fstream.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'include') diff --git a/include/fstream.h b/include/fstream.h index cb992f8..c62e5ad 100644 --- a/include/fstream.h +++ b/include/fstream.h @@ -144,6 +144,46 @@ SQFS_INTERNAL istream_t *istream_open_stdin(void); SQFS_INTERNAL ostream_t *ostream_compressor_create(ostream_t *strm, int comp_id); +/** + * @brief Create an input stream that transparently uncompresses data. + * + * @memberof istream_t + * + * This function creates an input stream that wraps an underlying input stream + * that is compressed and transparently uncompresses the data when reading + * from it. + * + * The new stream takes ownership of the wrapped stream and destroys it when + * the compressor stream is destroyed. If this function fails, the wrapped + * stream is also destroyed. + * + * @param strm A pointer to another stream that should be wrapped. + * @param comp_id An identifier describing the compressor to use. + * + * @return A pointer to an input stream on success, NULL on failure. + */ +SQFS_INTERNAL istream_t *istream_compressor_create(istream_t *strm, + int comp_id); + +/** + * @brief Probe the buffered data in an istream to check if it is compressed. + * + * @memberof istream_t + * + * This function peeks into the internal buffer of an input stream to check + * for magic signatures of various compressors. + * + * @param strm A pointer to an input stream to check + * @param probe A callback used to check if raw/decoded data matches an + * expected format. Returns 0 if not, -1 on failure and +1 + * on success. + * + * @return A compressor ID on success, 0 if no match was found, -1 on failure. + */ +SQFS_INTERNAL int istream_detect_compressor(istream_t *strm, + int (*probe)(const sqfs_u8 *data, + size_t size)); + /** * @brief Append a block of data to an output stream. * -- cgit v1.2.3