archive: replaced setup_stream() with open_stream()

The open_stream() method opens the input_stream.  This allows the
archive plugin to do its own initialization, and it also allows it to
use input_stream.data.  We can remove input_stream.archive now, which
was unnatural to have in the first place.
This commit is contained in:
Max Kellermann
2009-01-30 00:53:32 +01:00
parent dc1cc7e7e5
commit 82cfce76eb
7 changed files with 37 additions and 135 deletions

View File

@@ -148,22 +148,16 @@ bz2_close(struct archive_file *file)
/* single archive handling */
static void
bz2_setup_stream(struct archive_file *file, struct input_stream *is)
static bool
bz2_open_stream(struct archive_file *file, struct input_stream *is,
G_GNUC_UNUSED const char *path)
{
bz2_context *context = (bz2_context *) file;
//setup file ops
is->plugin = &bz2_inputplugin;
//insert back reference
is->archive = context;
is->data = context;
is->seekable = false;
}
static bool
bz2_is_open(struct input_stream *is, G_GNUC_UNUSED const char *url)
{
bz2_context *context = (bz2_context *) is->archive;
if (!bz2_alloc(context)) {
g_warning("alloc bz2 failed\n");
@@ -175,7 +169,7 @@ bz2_is_open(struct input_stream *is, G_GNUC_UNUSED const char *url)
static void
bz2_is_close(struct input_stream *is)
{
bz2_context *context = (bz2_context *) is->archive;
bz2_context *context = (bz2_context *) is->data;
bz2_destroy(context);
is->data = NULL;
}
@@ -211,7 +205,7 @@ bz2_fillbuffer(bz2_context *context,
static size_t
bz2_is_read(struct input_stream *is, void *ptr, size_t size)
{
bz2_context *context = (bz2_context *) is->archive;
bz2_context *context = (bz2_context *) is->data;
bz_stream *bzstream;
int bz_result;
size_t numBytes = size;
@@ -253,7 +247,7 @@ bz2_is_read(struct input_stream *is, void *ptr, size_t size)
static bool
bz2_is_eof(struct input_stream *is)
{
bz2_context *context = (bz2_context *) is->archive;
bz2_context *context = (bz2_context *) is->data;
if (context->last_bz_result == BZ_STREAM_END) {
return true;
@@ -283,7 +277,6 @@ static const char *const bz2_extensions[] = {
};
static const struct input_plugin bz2_inputplugin = {
.open = bz2_is_open,
.close = bz2_is_close,
.read = bz2_is_read,
.eof = bz2_is_eof,
@@ -296,7 +289,7 @@ const struct archive_plugin bz2_plugin = {
.open = bz2_open,
.scan_reset = bz2_scan_reset,
.scan_next = bz2_scan_next,
.setup_stream = bz2_setup_stream,
.open_stream = bz2_open_stream,
.close = bz2_close,
.suffixes = bz2_extensions
};

View File

@@ -136,23 +136,17 @@ iso_close(struct archive_file *file)
/* single archive handling */
static void
iso_setup_stream(struct archive_file *file, struct input_stream *is)
static bool
iso_open_stream(struct archive_file *file, struct input_stream *is,
const char *pathname)
{
iso_context *context = (iso_context *) file;
//setup file ops
is->plugin = &iso_inputplugin;
//insert back reference
is->archive = context;
is->data = context;
//we are not seekable
is->seekable = false;
}
static bool
iso_is_open(struct input_stream *is, const char *pathname)
{
iso_context *context = (iso_context *) is->archive;
context->statbuf = iso9660_ifs_stat_translate (context->iso, pathname);
@@ -168,7 +162,7 @@ iso_is_open(struct input_stream *is, const char *pathname)
static void
iso_is_close(struct input_stream *is)
{
iso_context *context = (iso_context *) is->archive;
iso_context *context = (iso_context *) is->data;
g_free(context->statbuf);
}
@@ -176,7 +170,7 @@ iso_is_close(struct input_stream *is)
static size_t
iso_is_read(struct input_stream *is, void *ptr, size_t size)
{
iso_context *context = (iso_context *) is->archive;
iso_context *context = (iso_context *) is->data;
int toread, readed = 0;
int no_blocks, cur_block;
size_t left_bytes = context->statbuf->size - context->cur_ofs;
@@ -213,7 +207,7 @@ iso_is_read(struct input_stream *is, void *ptr, size_t size)
static bool
iso_is_eof(struct input_stream *is)
{
iso_context *context = (iso_context *) is->archive;
iso_context *context = (iso_context *) is->data;
return (context->cur_ofs == context->statbuf->size);
}
@@ -238,7 +232,6 @@ static const char *const iso_extensions[] = {
};
static const struct input_plugin iso_inputplugin = {
.open = iso_is_open,
.close = iso_is_close,
.read = iso_is_read,
.eof = iso_is_eof,
@@ -251,7 +244,7 @@ const struct archive_plugin iso_plugin = {
.open = iso_open,
.scan_reset = iso_scan_reset,
.scan_next = iso_scan_next,
.setup_stream = iso_setup_stream,
.open_stream = iso_open_stream,
.close = iso_close,
.suffixes = iso_extensions
};

View File

@@ -103,24 +103,19 @@ zip_close(struct archive_file *file)
/* single archive handling */
static void
zip_setup_stream(struct archive_file *file, struct input_stream *is)
static bool
zip_open_stream(struct archive_file *file, struct input_stream *is,
const char *pathname)
{
zip_context *context = (zip_context *) file;
ZZIP_STAT z_stat;
//setup file ops
is->plugin = &zip_inputplugin;
//insert back reference
is->archive = context;
is->data = context;
//we are seekable (but its not recommendent to do so)
is->seekable = true;
}
static bool
zip_is_open(struct input_stream *is, const char *pathname)
{
zip_context *context = (zip_context *) is->archive;
ZZIP_STAT z_stat;
context->file = zzip_file_open(context->dir, pathname, 0);
if (!context->file) {
@@ -135,14 +130,14 @@ zip_is_open(struct input_stream *is, const char *pathname)
static void
zip_is_close(struct input_stream *is)
{
zip_context *context = (zip_context *) is->archive;
zip_context *context = (zip_context *) is->data;
zzip_file_close (context->file);
}
static size_t
zip_is_read(struct input_stream *is, void *ptr, size_t size)
{
zip_context *context = (zip_context *) is->archive;
zip_context *context = (zip_context *) is->data;
int ret;
ret = zzip_file_read(context->file, ptr, size);
if (ret < 0) {
@@ -155,7 +150,7 @@ zip_is_read(struct input_stream *is, void *ptr, size_t size)
static bool
zip_is_eof(struct input_stream *is)
{
zip_context *context = (zip_context *) is->archive;
zip_context *context = (zip_context *) is->data;
return ((size_t) zzip_tell(context->file) == context->length);
}
@@ -163,7 +158,7 @@ static bool
zip_is_seek(G_GNUC_UNUSED struct input_stream *is,
G_GNUC_UNUSED off_t offset, G_GNUC_UNUSED int whence)
{
zip_context *context = (zip_context *) is->archive;
zip_context *context = (zip_context *) is->data;
zzip_off_t ofs = zzip_seek(context->file, offset, whence);
if (ofs != -1) {
is->offset = ofs;
@@ -186,7 +181,6 @@ static const char *const zip_extensions[] = {
};
static const struct input_plugin zip_inputplugin = {
.open = zip_is_open,
.close = zip_is_close,
.read = zip_is_read,
.eof = zip_is_eof,
@@ -199,7 +193,7 @@ const struct archive_plugin zip_plugin = {
.open = zip_open,
.scan_reset = zip_scan_reset,
.scan_next = zip_scan_next,
.setup_stream = zip_setup_stream,
.open_stream = zip_open_stream,
.close = zip_close,
.suffixes = zip_extensions
};