aboutsummaryrefslogtreecommitdiff
path: root/src/tar.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/tar.h')
-rw-r--r--src/tar.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/tar.h b/src/tar.h
new file mode 100644
index 0000000..59b1c19
--- /dev/null
+++ b/src/tar.h
@@ -0,0 +1,50 @@
+#ifndef PW_TAR_H
+#define PW_TAR_H
+
+#include <SDL3/SDL_iostream.h>
+
+#define PW_TAR_BLOCK_SIZE 512
+
+/**
+ * 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,
+};
+
+/**
+ * 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.
+ */
+char const *pw_tar_read(struct pw_tar *tar, uint8_t **data, size_t *size,
+ size_t *blocks);
+
+/**
+ * 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