mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kutils: implement KArchive::data() argument to limit the data size
to be used (for example) in MIME type determination, i.e. read only a small chunk of the data Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
6f968d6f03
commit
7697b90bb2
2 changed files with 16 additions and 6 deletions
|
@ -201,7 +201,7 @@ public:
|
||||||
|
|
||||||
bool copyData(struct archive* readarchive, struct archive* writearchive);
|
bool copyData(struct archive* readarchive, struct archive* writearchive);
|
||||||
bool writeFile(struct archive* writearchive, QFile *file);
|
bool writeFile(struct archive* writearchive, QFile *file);
|
||||||
bool readData(struct archive* readarchive, QByteArray *buffer);
|
bool readData(struct archive* readarchive, QByteArray *buffer, const int maxsize);
|
||||||
|
|
||||||
QString tempFilePath() const;
|
QString tempFilePath() const;
|
||||||
|
|
||||||
|
@ -413,7 +413,7 @@ bool KArchivePrivate::writeFile(struct archive* writearchive, QFile *file)
|
||||||
return (readsize >= 0);
|
return (readsize >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KArchivePrivate::readData(struct archive* readarchive, QByteArray *buffer)
|
bool KArchivePrivate::readData(struct archive* readarchive, QByteArray *buffer, const int maxsize)
|
||||||
{
|
{
|
||||||
char readbuffer[KARCHIVE_BUFFSIZE];
|
char readbuffer[KARCHIVE_BUFFSIZE];
|
||||||
ssize_t readsize = archive_read_data(readarchive, readbuffer, sizeof(readbuffer));
|
ssize_t readsize = archive_read_data(readarchive, readbuffer, sizeof(readbuffer));
|
||||||
|
@ -424,11 +424,17 @@ bool KArchivePrivate::readData(struct archive* readarchive, QByteArray *buffer)
|
||||||
if (result != ARCHIVE_OK) {
|
if (result != ARCHIVE_OK) {
|
||||||
m_error = archive_error_string(readarchive);
|
m_error = archive_error_string(readarchive);
|
||||||
kDebug() << "archive_read_data" << m_error;
|
kDebug() << "archive_read_data" << m_error;
|
||||||
|
buffer->clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->append(readbuffer, readsize);
|
buffer->append(readbuffer, readsize);
|
||||||
|
|
||||||
|
if (maxsize > 0 && buffer->size() >= maxsize) {
|
||||||
|
buffer->resize(maxsize);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
readsize = archive_read_data(readarchive, readbuffer, sizeof(readbuffer));
|
readsize = archive_read_data(readarchive, readbuffer, sizeof(readbuffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1151,7 +1157,7 @@ KArchiveEntry KArchive::entry(const QString &path) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QByteArray KArchive::data(const QString &path) const
|
QByteArray KArchive::data(const QString &path, const int maxsize) const
|
||||||
{
|
{
|
||||||
QByteArray result;
|
QByteArray result;
|
||||||
|
|
||||||
|
@ -1185,7 +1191,7 @@ QByteArray KArchive::data(const QString &path) const
|
||||||
const QByteArray pathname = archive_entry_pathname(entry);
|
const QByteArray pathname = archive_entry_pathname(entry);
|
||||||
const QString pathnamestring = QFile::decodeName(pathname);
|
const QString pathnamestring = QFile::decodeName(pathname);
|
||||||
if (pathnamestring == path) {
|
if (pathnamestring == path) {
|
||||||
d->readData(readarchive, &result);
|
d->readData(readarchive, &result, maxsize);
|
||||||
|
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -135,8 +135,12 @@ public:
|
||||||
QList<KArchiveEntry> list(const QString &path = QString()) const;
|
QList<KArchiveEntry> list(const QString &path = QString()) const;
|
||||||
//! @brief Get entry information for path in archive
|
//! @brief Get entry information for path in archive
|
||||||
KArchiveEntry entry(const QString &path) const;
|
KArchiveEntry entry(const QString &path) const;
|
||||||
//! @brief Get data for path in archive
|
/*!
|
||||||
QByteArray data(const QString &path) const;
|
@brief Get data for path in archive
|
||||||
|
@param path path to get data for
|
||||||
|
@param maxsize the limit for data, if zero then it is as if there is no limit
|
||||||
|
*/
|
||||||
|
QByteArray data(const QString &path, const int maxsize = 0) const;
|
||||||
|
|
||||||
//! @brief Returns if path is readable archive
|
//! @brief Returns if path is readable archive
|
||||||
bool isReadable() const;
|
bool isReadable() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue