Wow, I completely overlooked that. I was convinced that Gzip.input/Gzip.really_input returned the number of *compressed* characters read. I misread "uncompresses up to len characters" as "advances the compressed buffer up to len characters". The phrase "[Gzip.input] returns the actual number of characters read" didn't help me either. Anyway, thanks a lot, it's much simpler than I expected! On Mon, Feb 2, 2015 at 6:38 PM, David Allsopp wrote: > Dhek Uir wrote: > > But since camlzip does not have an input_value function, it seems I must > set up > > a buffer to decompress the data, then use Marshal to obtain input data > from the > > decompressed buffer. But if I use Marshal.from_string to read the > decompressed > > buffer, then I need to keep track of its position (which is not returned > by > > Marshal.from_string), and check whether the buffer is nearly empty, so > that I > > may need to re-read from the compressed in_channel, etc, etc. Did I miss > the > > right function again? > > Marshal has everything you need: > > let input_value ch = > let header = String.create Marshal.header_size > in > Gzip.really_input ch header 0 Marshal.header_size; > let buffer = String.create (Marshal.total_size header 0) > in > Gzip.really_input ch buffer Marshal.header_size (Marshal.data_size > header 0); > String.unsafe_blit header 0 buffer 0 Marshal.header_size; > Marshal.from_string buffer 0 > > > David >