From 7c630d727e0e3bbc0664b662a7ed397c4c621799 Mon Sep 17 00:00:00 2001 From: Ben Lawrence Date: Mon, 9 Dec 2024 11:27:01 +0000 Subject: [PATCH] Document the validate functions in the README --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 8ae0c2e..b902096 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,19 @@ information along with the compressed stream. During decoding, the library may read up to `STREAMVBYTE_PADDING` extra bytes from the input buffer (these bytes are read but never used). +To verify that the expected size of a stream is correct you may validate it before +decoding: +```C +// compressedbuffer, compsize, recovdata, N are as above +if (streamvbyte_validate_stream(compressedbuffer, compsize, N)) { + // the stream is safe to decode + streamvbyte_decode(compressedbuffer, recovdata, N); +} else { + // there's a mismatch between the expected size of the data (N) and the contents of + // the stream, so performing a decode is unsafe since the behaviour is undefined +} +``` +