Commit 4cab151e authored by Max Kellermann's avatar Max Kellermann

input/zzip: add constructor/destructor

parent 8ac9b77e
...@@ -138,6 +138,30 @@ struct ZzipInputStream { ...@@ -138,6 +138,30 @@ struct ZzipInputStream {
ZzipArchiveFile *archive; ZzipArchiveFile *archive;
ZZIP_FILE *file; ZZIP_FILE *file;
ZzipInputStream(ZzipArchiveFile &_archive, const char *uri,
Mutex &mutex, Cond &cond,
ZZIP_FILE *_file)
:archive(&_archive), file(_file) {
input_stream_init(&base, &zzip_input_plugin, uri,
mutex, cond);
base.ready = true;
//we are seekable (but its not recommendent to do so)
base.seekable = true;
ZZIP_STAT z_stat;
zzip_file_stat(file, &z_stat);
base.size = z_stat.st_size;
refcount_inc(&archive->ref);
}
~ZzipInputStream() {
zzip_file_close(file);
archive->Unref();
input_stream_deinit(&base);
}
}; };
static struct input_stream * static struct input_stream *
...@@ -147,30 +171,18 @@ zzip_archive_open_stream(struct archive_file *file, ...@@ -147,30 +171,18 @@ zzip_archive_open_stream(struct archive_file *file,
GError **error_r) GError **error_r)
{ {
ZzipArchiveFile *context = (ZzipArchiveFile *) file; ZzipArchiveFile *context = (ZzipArchiveFile *) file;
ZZIP_STAT z_stat;
ZzipInputStream *zis = g_new(ZzipInputStream, 1);
input_stream_init(&zis->base, &zzip_input_plugin, pathname,
mutex, cond);
zis->archive = context; ZZIP_FILE *_file = zzip_file_open(context->dir, pathname, 0);
zis->file = zzip_file_open(context->dir, pathname, 0); if (_file == nullptr) {
if (zis->file == NULL) {
g_free(zis);
g_set_error(error_r, zzip_quark(), 0, g_set_error(error_r, zzip_quark(), 0,
"not found in the ZIP file: %s", pathname); "not found in the ZIP file: %s", pathname);
return NULL; return NULL;
} }
zis->base.ready = true; ZzipInputStream *zis =
//we are seekable (but its not recommendent to do so) new ZzipInputStream(*context, pathname,
zis->base.seekable = true; mutex, cond,
_file);
zzip_file_stat(zis->file, &z_stat);
zis->base.size = z_stat.st_size;
refcount_inc(&context->ref);
return &zis->base; return &zis->base;
} }
...@@ -179,10 +191,7 @@ zzip_input_close(struct input_stream *is) ...@@ -179,10 +191,7 @@ zzip_input_close(struct input_stream *is)
{ {
ZzipInputStream *zis = (ZzipInputStream *)is; ZzipInputStream *zis = (ZzipInputStream *)is;
zzip_file_close(zis->file); delete zis;
zzip_archive_close(&zis->archive->base);
input_stream_deinit(&zis->base);
g_free(zis);
} }
static size_t static size_t
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment