#ifndef PW_TAR_H #define PW_TAR_H #include #include #define PW_TAR_BLOCK_SIZE 512 #define PW_TAR_PATH_MAX 257 #define PW_TAR_SIZE_MAX ((SIZE_MAX / PW_TAR_BLOCK_SIZE) * PW_TAR_BLOCK_SIZE) /** * A UStar archive stream. */ struct pw_tar { SDL_IOStream *stream; uint8_t block[PW_TAR_BLOCK_SIZE]; }; /** * Specify Tar archive stream open mode. */ enum pw_tar_open_flag { PW_TAR_OPEN_READ, PW_TAR_OPEN_WRITE, }; /** * A read Tar entry. */ struct pw_tar_entry { char path[PW_TAR_PATH_MAX]; uint8_t *data; size_t size; size_t capacity; size_t blocks; }; /** * Opens a new Tar reader. */ struct pw_tar *pw_tar_open(char const *path, enum pw_tar_open_flag flag); /** * Closes and frees the Tar reader. */ void pw_tar_free(struct pw_tar *tar); /** * Reads the next entry in a Tar file, returning the its file name. * * Sets `data` to the file contents with `size`, `data` is allocated with * `blocks * PW_TAR_BLOCK_SIZE` bytes, and must be freed by the caller. */ bool pw_tar_read(struct pw_tar *tar, struct pw_tar_entry *entry); /** * Writes an entry to the Tar file. Write NULL data to indicate the end of * the archive. */ bool pw_tar_write(struct pw_tar *tar, char const *path, uint8_t const *data, size_t size); #endif