input/plugins: make InputStream the base class
Prepare for adding virtual methods.
This commit is contained in:
@@ -88,9 +88,7 @@ public:
|
||||
Error &error) override;
|
||||
};
|
||||
|
||||
struct Bzip2InputStream {
|
||||
InputStream base;
|
||||
|
||||
struct Bzip2InputStream final : public InputStream {
|
||||
Bzip2ArchiveFile *archive;
|
||||
|
||||
bool eof;
|
||||
@@ -130,7 +128,7 @@ Bzip2InputStream::Open(Error &error)
|
||||
return false;
|
||||
}
|
||||
|
||||
base.ready = true;
|
||||
SetReady();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -157,9 +155,10 @@ bz2_open(Path pathname, Error &error)
|
||||
|
||||
/* single archive handling */
|
||||
|
||||
Bzip2InputStream::Bzip2InputStream(Bzip2ArchiveFile &_context, const char *uri,
|
||||
Mutex &mutex, Cond &cond)
|
||||
:base(bz2_inputplugin, uri, mutex, cond),
|
||||
Bzip2InputStream::Bzip2InputStream(Bzip2ArchiveFile &_context,
|
||||
const char *_uri,
|
||||
Mutex &_mutex, Cond &_cond)
|
||||
:InputStream(bz2_inputplugin, _uri, _mutex, _cond),
|
||||
archive(&_context), eof(false)
|
||||
{
|
||||
archive->Ref();
|
||||
@@ -181,7 +180,7 @@ Bzip2ArchiveFile::OpenStream(const char *path,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &bis->base;
|
||||
return bis;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -140,21 +140,19 @@ Iso9660ArchiveFile::Visit(ArchiveVisitor &visitor)
|
||||
|
||||
/* single archive handling */
|
||||
|
||||
class Iso9660InputStream {
|
||||
InputStream base;
|
||||
|
||||
class Iso9660InputStream final : public InputStream {
|
||||
Iso9660ArchiveFile &archive;
|
||||
|
||||
iso9660_stat_t *statbuf;
|
||||
|
||||
public:
|
||||
Iso9660InputStream(Iso9660ArchiveFile &_archive, const char *uri,
|
||||
Mutex &mutex, Cond &cond,
|
||||
Iso9660InputStream(Iso9660ArchiveFile &_archive, const char *_uri,
|
||||
Mutex &_mutex, Cond &_cond,
|
||||
iso9660_stat_t *_statbuf)
|
||||
:base(iso9660_input_plugin, uri, mutex, cond),
|
||||
:InputStream(iso9660_input_plugin, _uri, _mutex, _cond),
|
||||
archive(_archive), statbuf(_statbuf) {
|
||||
base.ready = true;
|
||||
base.size = statbuf->size;
|
||||
size = statbuf->size;
|
||||
SetReady();
|
||||
|
||||
archive.Ref();
|
||||
}
|
||||
@@ -164,10 +162,6 @@ public:
|
||||
archive.Unref();
|
||||
}
|
||||
|
||||
InputStream *Get() {
|
||||
return &base;
|
||||
}
|
||||
|
||||
size_t Read(void *ptr, size_t size, Error &error);
|
||||
};
|
||||
|
||||
@@ -183,10 +177,8 @@ Iso9660ArchiveFile::OpenStream(const char *pathname,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Iso9660InputStream *iis =
|
||||
new Iso9660InputStream(*this, pathname, mutex, cond,
|
||||
statbuf);
|
||||
return iis->Get();
|
||||
return new Iso9660InputStream(*this, pathname, mutex, cond,
|
||||
statbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -198,22 +190,22 @@ iso9660_input_close(InputStream *is)
|
||||
}
|
||||
|
||||
inline size_t
|
||||
Iso9660InputStream::Read(void *ptr, size_t size, Error &error)
|
||||
Iso9660InputStream::Read(void *ptr, size_t read_size, Error &error)
|
||||
{
|
||||
int readed = 0;
|
||||
int no_blocks, cur_block;
|
||||
size_t left_bytes = statbuf->size - base.offset;
|
||||
size_t left_bytes = statbuf->size - offset;
|
||||
|
||||
if (left_bytes < size) {
|
||||
no_blocks = CEILING(left_bytes,ISO_BLOCKSIZE);
|
||||
if (left_bytes < read_size) {
|
||||
no_blocks = CEILING(left_bytes, ISO_BLOCKSIZE);
|
||||
} else {
|
||||
no_blocks = size / ISO_BLOCKSIZE;
|
||||
no_blocks = read_size / ISO_BLOCKSIZE;
|
||||
}
|
||||
|
||||
if (no_blocks == 0)
|
||||
return 0;
|
||||
|
||||
cur_block = base.offset / ISO_BLOCKSIZE;
|
||||
cur_block = offset / ISO_BLOCKSIZE;
|
||||
|
||||
readed = archive.SeekRead(ptr, statbuf->lsn + cur_block,
|
||||
no_blocks);
|
||||
@@ -224,11 +216,11 @@ Iso9660InputStream::Read(void *ptr, size_t size, Error &error)
|
||||
(unsigned long)cur_block);
|
||||
return 0;
|
||||
}
|
||||
if (left_bytes < size) {
|
||||
if (left_bytes < read_size) {
|
||||
readed = left_bytes;
|
||||
}
|
||||
|
||||
base.offset += readed;
|
||||
offset += readed;
|
||||
return readed;
|
||||
}
|
||||
|
||||
|
@@ -97,25 +97,24 @@ ZzipArchiveFile::Visit(ArchiveVisitor &visitor)
|
||||
|
||||
/* single archive handling */
|
||||
|
||||
struct ZzipInputStream {
|
||||
InputStream base;
|
||||
|
||||
struct ZzipInputStream final : public InputStream {
|
||||
ZzipArchiveFile *archive;
|
||||
|
||||
ZZIP_FILE *file;
|
||||
|
||||
ZzipInputStream(ZzipArchiveFile &_archive, const char *uri,
|
||||
Mutex &mutex, Cond &cond,
|
||||
ZzipInputStream(ZzipArchiveFile &_archive, const char *_uri,
|
||||
Mutex &_mutex, Cond &_cond,
|
||||
ZZIP_FILE *_file)
|
||||
:base(zzip_input_plugin, uri, mutex, cond),
|
||||
:InputStream(zzip_input_plugin, _uri, _mutex, _cond),
|
||||
archive(&_archive), file(_file) {
|
||||
base.ready = true;
|
||||
//we are seekable (but its not recommendent to do so)
|
||||
base.seekable = true;
|
||||
seekable = true;
|
||||
|
||||
ZZIP_STAT z_stat;
|
||||
zzip_file_stat(file, &z_stat);
|
||||
base.size = z_stat.st_size;
|
||||
size = z_stat.st_size;
|
||||
|
||||
SetReady();
|
||||
|
||||
archive->ref.Increment();
|
||||
}
|
||||
@@ -138,11 +137,9 @@ ZzipArchiveFile::OpenStream(const char *pathname,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ZzipInputStream *zis =
|
||||
new ZzipInputStream(*this, pathname,
|
||||
mutex, cond,
|
||||
_file);
|
||||
return &zis->base;
|
||||
return new ZzipInputStream(*this, pathname,
|
||||
mutex, cond,
|
||||
_file);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Reference in New Issue
Block a user