I’m writing a library to support reading and writing BioVision Hierarchical files.
This widely used format for 3D animation consists of a number of skeleton definitions, then the number of frames of data, then the frames of data themselves. Other than this count, the data could be written in append mode, which is a pretty reasonable thing to want to do with an animation format. In particular, one might want to ‘drip feed’ the frames in real time.
Since the frame count isn’t actually used by readers that can wait for more data, I’d like to provide the option to only go back and write the frame count when the file is closed. This demands a hook into close. But as a library, I’d like all this to be transparent to the user. If feels unProloglike to force this on the user.
Is there some way to hook file close? Hopefully without redefining the system predicate (which seems aggressive) or installing a compile time hook (which also seems extreme, and fragile)?
There needs to be an open_bvh_file anyway, to get the skeleton, but I’d rather not wrap the stream just so it can’t be closed with close/1