Hi there,
I have some python code that:
- Takes a BLOB from a database which is compressed.
- Calls an uncompression routine in C that uncompresses the data.
- Writes the uncompressed data to a file.
It uses ctypes to call the C routine, which is in a shared library.
This mostly works, except for the actual writing to the file. To uncompress, I get the data uncompressed into a python buffer, created using the ctypes create_string_buffer
method:
c_uncompData_p = create_string_buffer(64000)
so the uncompression call is like this:
c_uncompSize = mylib.explodeCharBuffer (c_data_p, c_data_len, c_uncompData_p)
The size of the resulting uncompressed data is returned as the return value.
But... I have no idea how to force python on only write c_uncompSize
bytes out - if I do:
myfile.write (c_uncompData_p.raw)
it writes the whole 64k buffer out (the data is binary - so it is not null terminated).
So, my question is - using Python 2.5 how do I get c_uncompSize bytes printed out, rather than the whole 64k?
Thanks Jamie