archive/zzip: added struct zzip_input_stream
Don't use the zzip_archive object for the input_stream.
This commit is contained in:
parent
55fbb67cfb
commit
9862521aec
@ -35,7 +35,6 @@ struct zzip_archive {
|
|||||||
struct archive_file base;
|
struct archive_file base;
|
||||||
|
|
||||||
ZZIP_DIR *dir;
|
ZZIP_DIR *dir;
|
||||||
ZZIP_FILE *file;
|
|
||||||
GSList *list;
|
GSList *list;
|
||||||
GSList *iter;
|
GSList *iter;
|
||||||
};
|
};
|
||||||
@ -117,27 +116,39 @@ zzip_archive_close(struct archive_file *file)
|
|||||||
|
|
||||||
/* single archive handling */
|
/* single archive handling */
|
||||||
|
|
||||||
|
struct zzip_input_stream {
|
||||||
|
struct zzip_archive *archive;
|
||||||
|
|
||||||
|
ZZIP_FILE *file;
|
||||||
|
};
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
zzip_archive_open_stream(struct archive_file *file, struct input_stream *is,
|
zzip_archive_open_stream(struct archive_file *file, struct input_stream *is,
|
||||||
const char *pathname, GError **error_r)
|
const char *pathname, GError **error_r)
|
||||||
{
|
{
|
||||||
struct zzip_archive *context = (struct zzip_archive *) file;
|
struct zzip_archive *context = (struct zzip_archive *) file;
|
||||||
|
struct zzip_input_stream *zis;
|
||||||
ZZIP_STAT z_stat;
|
ZZIP_STAT z_stat;
|
||||||
|
|
||||||
//setup file ops
|
zis = g_new(struct zzip_input_stream, 1);
|
||||||
is->plugin = &zzip_input_plugin;
|
|
||||||
//insert back reference
|
|
||||||
is->data = context;
|
|
||||||
//we are seekable (but its not recommendent to do so)
|
|
||||||
is->seekable = true;
|
|
||||||
|
|
||||||
context->file = zzip_file_open(context->dir, pathname, 0);
|
zis->archive = context;
|
||||||
if (!context->file) {
|
zis->file = zzip_file_open(context->dir, pathname, 0);
|
||||||
|
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 false;
|
return false;
|
||||||
}
|
}
|
||||||
zzip_file_stat(context->file, &z_stat);
|
|
||||||
|
//setup file ops
|
||||||
|
is->plugin = &zzip_input_plugin;
|
||||||
|
//insert back reference
|
||||||
|
is->data = zis;
|
||||||
|
//we are seekable (but its not recommendent to do so)
|
||||||
|
is->seekable = true;
|
||||||
|
|
||||||
|
zzip_file_stat(zis->file, &z_stat);
|
||||||
is->size = z_stat.st_size;
|
is->size = z_stat.st_size;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -145,26 +156,28 @@ zzip_archive_open_stream(struct archive_file *file, struct input_stream *is,
|
|||||||
static void
|
static void
|
||||||
zzip_input_close(struct input_stream *is)
|
zzip_input_close(struct input_stream *is)
|
||||||
{
|
{
|
||||||
struct zzip_archive *context = (struct zzip_archive *) is->data;
|
struct zzip_input_stream *zis = (struct zzip_input_stream *)is->data;
|
||||||
zzip_file_close (context->file);
|
|
||||||
|
|
||||||
zzip_archive_close((struct archive_file *)context);
|
zzip_file_close(zis->file);
|
||||||
|
zzip_archive_close(&zis->archive->base);
|
||||||
|
g_free(zis);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
zzip_input_read(struct input_stream *is, void *ptr, size_t size,
|
zzip_input_read(struct input_stream *is, void *ptr, size_t size,
|
||||||
GError **error_r)
|
GError **error_r)
|
||||||
{
|
{
|
||||||
struct zzip_archive *context = (struct zzip_archive *) is->data;
|
struct zzip_input_stream *zis = (struct zzip_input_stream *)is->data;
|
||||||
int ret;
|
int ret;
|
||||||
ret = zzip_file_read(context->file, ptr, size);
|
|
||||||
|
ret = zzip_file_read(zis->file, ptr, size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
g_set_error(error_r, zzip_quark(), ret,
|
g_set_error(error_r, zzip_quark(), ret,
|
||||||
"zzip_file_read() has failed");
|
"zzip_file_read() has failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
is->offset = zzip_tell(context->file);
|
is->offset = zzip_tell(zis->file);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -172,16 +185,17 @@ zzip_input_read(struct input_stream *is, void *ptr, size_t size,
|
|||||||
static bool
|
static bool
|
||||||
zzip_input_eof(struct input_stream *is)
|
zzip_input_eof(struct input_stream *is)
|
||||||
{
|
{
|
||||||
struct zzip_archive *context = (struct zzip_archive *) is->data;
|
struct zzip_input_stream *zis = (struct zzip_input_stream *)is->data;
|
||||||
return (goffset)zzip_tell(context->file) == is->size;
|
|
||||||
|
return (goffset)zzip_tell(zis->file) == is->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
zzip_input_seek(struct input_stream *is,
|
zzip_input_seek(struct input_stream *is,
|
||||||
goffset offset, int whence, GError **error_r)
|
goffset offset, int whence, GError **error_r)
|
||||||
{
|
{
|
||||||
struct zzip_archive *context = (struct zzip_archive *) is->data;
|
struct zzip_input_stream *zis = (struct zzip_input_stream *)is->data;
|
||||||
zzip_off_t ofs = zzip_seek(context->file, offset, whence);
|
zzip_off_t ofs = zzip_seek(zis->file, offset, whence);
|
||||||
if (ofs != -1) {
|
if (ofs != -1) {
|
||||||
g_set_error(error_r, zzip_quark(), ofs,
|
g_set_error(error_r, zzip_quark(), ofs,
|
||||||
"zzip_seek() has failed");
|
"zzip_seek() has failed");
|
||||||
|
Loading…
Reference in New Issue
Block a user