mbroemme / libmpq

libmpq is a library for manipulating MPQ (MoPaQ) archives, which are used by Blizzard in most of their games (e.g., Diablo, Diablo 2, StarCraft, WarCraft 3, and World of Warcraft).
http://libmpq.org
GNU General Public License v2.0
37 stars 13 forks source link

Streaming API for files #11

Closed glebm closed 3 years ago

glebm commented 3 years ago

It'd be very useful to have a streaming API for files with read/seek functions, so that it can be wrapped as e.g. SDL_RWops for audio streaming.

glebm commented 3 years ago

A function that can convert file position to block number + position is probably sufficient to implement streaming API user-side:

/* returns the block number, size, and block start position for the given position in the unpacked file. */
int32_t libmpq__block_seek(mpq_archive_s *mpq_archive, uint32_t file_number, uint32_t file_position, uint32_t *block_number, libmpq__off_t *block_size, uint32_t *block_start_position) {

I'll give it a go

glebm commented 3 years ago

If the client code makes the assumption that all block sizes except the last one are equal, such a function is not necessary, but I don't know if it's OK for client code to make this assumption.