diff options
Diffstat (limited to 'src/archive/plugins')
-rw-r--r-- | src/archive/plugins/Bzip2ArchivePlugin.cxx | 45 | ||||
-rw-r--r-- | src/archive/plugins/Iso9660ArchivePlugin.cxx | 27 | ||||
-rw-r--r-- | src/archive/plugins/ZzipArchivePlugin.cxx | 43 |
3 files changed, 41 insertions, 74 deletions
diff --git a/src/archive/plugins/Bzip2ArchivePlugin.cxx b/src/archive/plugins/Bzip2ArchivePlugin.cxx index 213b7d38c..d349b537f 100644 --- a/src/archive/plugins/Bzip2ArchivePlugin.cxx +++ b/src/archive/plugins/Bzip2ArchivePlugin.cxx @@ -102,6 +102,10 @@ struct Bzip2InputStream final : public InputStream { ~Bzip2InputStream(); bool Open(Error &error); + + /* virtual methods from InputStream */ + bool IsEOF() override; + size_t Read(void *ptr, size_t size, Error &error) override; }; extern const InputPlugin bz2_inputplugin; @@ -198,30 +202,26 @@ bz2_fillbuffer(Bzip2InputStream *bis, Error &error) return true; } -static size_t -bz2_is_read(InputStream *is, void *ptr, size_t length, - Error &error) +size_t +Bzip2InputStream::Read(void *ptr, size_t length, Error &error) { - Bzip2InputStream *bis = (Bzip2InputStream *)is; - bz_stream *bzstream; int bz_result; size_t nbytes = 0; - if (bis->eof) + if (eof) return 0; - bzstream = &bis->bzstream; - bzstream->next_out = (char *)ptr; - bzstream->avail_out = length; + bzstream.next_out = (char *)ptr; + bzstream.avail_out = length; do { - if (!bz2_fillbuffer(bis, error)) + if (!bz2_fillbuffer(this, error)) return 0; - bz_result = BZ2_bzDecompress(bzstream); + bz_result = BZ2_bzDecompress(&bzstream); if (bz_result == BZ_STREAM_END) { - bis->eof = true; + eof = true; break; } @@ -230,20 +230,18 @@ bz2_is_read(InputStream *is, void *ptr, size_t length, "BZ2_bzDecompress() has failed"); return 0; } - } while (bzstream->avail_out == length); + } while (bzstream.avail_out == length); - nbytes = length - bzstream->avail_out; - is->offset += nbytes; + nbytes = length - bzstream.avail_out; + offset += nbytes; return nbytes; } -static bool -bz2_is_eof(InputStream *is) +bool +Bzip2InputStream::IsEOF() { - Bzip2InputStream *bis = (Bzip2InputStream *)is; - - return bis->eof; + return eof; } /* exported structures */ @@ -258,13 +256,6 @@ const InputPlugin bz2_inputplugin = { nullptr, nullptr, nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - bz2_is_read, - bz2_is_eof, - nullptr, }; const ArchivePlugin bz2_archive_plugin = { diff --git a/src/archive/plugins/Iso9660ArchivePlugin.cxx b/src/archive/plugins/Iso9660ArchivePlugin.cxx index 0a9cb8214..e5c3fd062 100644 --- a/src/archive/plugins/Iso9660ArchivePlugin.cxx +++ b/src/archive/plugins/Iso9660ArchivePlugin.cxx @@ -162,7 +162,9 @@ public: archive.Unref(); } - size_t Read(void *ptr, size_t size, Error &error); + /* virtual methods from InputStream */ + bool IsEOF() override; + size_t Read(void *ptr, size_t size, Error &error) override; }; InputStream * @@ -181,7 +183,7 @@ Iso9660ArchiveFile::OpenStream(const char *pathname, statbuf); } -inline size_t +size_t Iso9660InputStream::Read(void *ptr, size_t read_size, Error &error) { int readed = 0; @@ -216,18 +218,10 @@ Iso9660InputStream::Read(void *ptr, size_t read_size, Error &error) return readed; } -static size_t -iso9660_input_read(InputStream *is, void *ptr, size_t size, - Error &error) +bool +Iso9660InputStream::IsEOF() { - Iso9660InputStream *iis = (Iso9660InputStream *)is; - return iis->Read(ptr, size, error); -} - -static bool -iso9660_input_eof(InputStream *is) -{ - return is->offset == is->size; + return offset == size; } /* exported structures */ @@ -242,13 +236,6 @@ const InputPlugin iso9660_input_plugin = { nullptr, nullptr, nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - iso9660_input_read, - iso9660_input_eof, - nullptr, }; const ArchivePlugin iso9660_archive_plugin = { diff --git a/src/archive/plugins/ZzipArchivePlugin.cxx b/src/archive/plugins/ZzipArchivePlugin.cxx index 4eafe4aeb..53b6b9f93 100644 --- a/src/archive/plugins/ZzipArchivePlugin.cxx +++ b/src/archive/plugins/ZzipArchivePlugin.cxx @@ -123,6 +123,11 @@ struct ZzipInputStream final : public InputStream { zzip_file_close(file); archive->Unref(); } + + /* virtual methods from InputStream */ + bool IsEOF() override; + size_t Read(void *ptr, size_t size, Error &error) override; + bool Seek(offset_type offset, int whence, Error &error) override; }; InputStream * @@ -142,41 +147,32 @@ ZzipArchiveFile::OpenStream(const char *pathname, _file); } -static size_t -zzip_input_read(InputStream *is, void *ptr, size_t size, - Error &error) +size_t +ZzipInputStream::Read(void *ptr, size_t read_size, Error &error) { - ZzipInputStream *zis = (ZzipInputStream *)is; - int ret; - - ret = zzip_file_read(zis->file, ptr, size); + int ret = zzip_file_read(file, ptr, read_size); if (ret < 0) { error.Set(zzip_domain, "zzip_file_read() has failed"); return 0; } - is->offset = zzip_tell(zis->file); - + offset = zzip_tell(file); return ret; } -static bool -zzip_input_eof(InputStream *is) +bool +ZzipInputStream::IsEOF() { - ZzipInputStream *zis = (ZzipInputStream *)is; - - return (InputPlugin::offset_type)zzip_tell(zis->file) == is->size; + return (InputPlugin::offset_type)zzip_tell(file) == size; } -static bool -zzip_input_seek(InputStream *is, InputPlugin::offset_type offset, - int whence, Error &error) +bool +ZzipInputStream::Seek(offset_type new_offset, int whence, Error &error) { - ZzipInputStream *zis = (ZzipInputStream *)is; - zzip_off_t ofs = zzip_seek(zis->file, offset, whence); + zzip_off_t ofs = zzip_seek(file, new_offset, whence); if (ofs != -1) { error.Set(zzip_domain, "zzip_seek() has failed"); - is->offset = ofs; + offset = ofs; return true; } return false; @@ -194,13 +190,6 @@ const InputPlugin zzip_input_plugin = { nullptr, nullptr, nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - zzip_input_read, - zzip_input_eof, - zzip_input_seek, }; const ArchivePlugin zzip_archive_plugin = { |