--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2025 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <pakfire/archive_writer.h>
+
+struct pakfire_archive_writer {
+ struct pakfire_ctx* ctx;
+ int nrefs;
+
+ // Pakfire
+ struct pakfire* pakfire;
+
+ // Format
+ pakfire_archive_writer_format format;
+
+ // File Handle
+ FILE* f;
+};
+
+static void pakfire_archive_writer_free(struct pakfire_archive_writer* self) {
+ if (self->pakfire)
+ pakfire_unref(self->pakfire);
+ if (self->ctx)
+ pakfire_ctx_unref(self->ctx);
+ free(self);
+}
+
+int pakfire_archive_writer_create(struct pakfire_archive_writer** writer,
+ struct pakfire* pakfire, pakfire_archive_writer_format format, FILE* f) {
+ struct pakfire_archive_writer* self = NULL;
+ int r;
+
+ // Allocate some memory
+ self = calloc(1, sizeof(*self));
+ if (!self)
+ return -errno;
+
+ // Store a reference to the context
+ self->ctx = pakfire_ctx(pakfire);
+
+ // Store a reference to Pakfire
+ self->pakfire = pakfire_ref(pakfire);
+
+ // Initialize the reference counter
+ self->nrefs = 1;
+
+ // Store the format
+ switch (format) {
+ case PAKFIRE_FORMAT_ARCHIVE:
+ self->format = format;
+ break;
+
+ default:
+ ERROR(self->ctx, "Invalid archive format\n");
+ r = -EINVAL;
+ goto ERROR;
+ }
+
+ // Store the file handle
+ self->f = f;
+
+ // Return the pointer
+ *writer = self;
+ return 0;
+
+ERROR:
+ pakfire_archive_writer_free(self);
+ return r;
+}
+
+struct pakfire_archive_writer* pakfire_archive_writer_ref(struct pakfire_archive_writer* self) {
+ ++self->nrefs;
+
+ return self;
+}
+
+struct pakfire_archive_writer* pakfire_archive_writer_unref(struct pakfire_archive_writer* self) {
+ if (--self->nrefs > 0)
+ return self;
+
+ pakfire_archive_writer_free(self);
+ return NULL;
+}
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2025 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef PAKFIRE_ARCHIVE_WRITER_H
+#define PAKFIRE_ARCHIVE_WRITER_H
+
+#include <stdio.h>
+
+#include <pakfire/pakfire.h>
+
+struct pakfire_archive_writer;
+
+typedef enum pakfire_archive_writer_formats {
+ PAKFIRE_FORMAT_ARCHIVE,
+} pakfire_archive_writer_format;
+
+int pakfire_archive_writer_create(struct pakfire_archive_writer** writer,
+ struct pakfire* pakfire, pakfire_archive_writer_format format, FILE* f);
+
+struct pakfire_archive_writer* pakfire_archive_writer_ref(struct pakfire_archive_writer* self);
+struct pakfire_archive_writer* pakfire_archive_writer_unref(struct pakfire_archive_writer* self);
+
+#endif /* PAKFIRE_ARCHIVE_WRITER_H */